如何使网站离线可用
我想让我的网站可以离线使用,即使用户清除了缓存和 cookie。有可能吗?我也在处理数据库。是否可以离线处理数据库?
I want to make my website available offline even if the user clears the cache and cookies. Is is possible? Also I am dealing with database. Is is possible to handle databases offline?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
不,如果您的数据库在线托管。那么您需要 PHP/ASP(无论您使用什么来处理数据库)的互联网连接来连接/通信到数据库
No, if your databases are housed online. then you need a internet connection for the PHP/ASP (whatever you're using to deal with DBs) to connect/communicate to the DB's
要在本地存储数据并离线访问它们,请查看 Gears 和 网络存储。
主要问题是您希望为您的网站提供何种程度的功能。它总是需要在客户端(用户)端进行一些工作来“存储”又名。离线保存您的网站。您必须将所有功能存储在用户存储的一个页面中(无论是 Flash 电影还是某些 Javascript 代码)。
For storing data locally and accessing them offline take a look at Gears and Web Storage.
The main problem is what degree of functionality you want to provide with your website. It always requires some work on the client (user) side to "store" aka. save your website offline. You would have to store all your functionality in one page that the user stores (be it a Flash movie or some Javascript-Code).
您可以使用简单的命令在本地下载整个网站,所有链接都可以正常工作。
对于 https url,您需要再添加一项属性,如下所示:
You can use simple command to download whole website locally with all links working properly.
For https url you need to add one more property like below :
用户可以使用 Chrome 存储单个网页的本地副本(右键单击“另存为”),它将存储所有资源(图像、CSS , js) 需要离线完全加载页面。其他浏览器也有类似的选项。
您可以使用wget镜像整个网站以供离线浏览。
当然,这些选项都不会处理您的网站/页面的数据库驱动元素。
如果您想离线模拟数据库或页面的动态元素,那么 Google Gears 可能是最接近的到你正在寻找的东西,但我认为它去年被谷歌弃用了。
A user could store a local copy of a single webpage using Chrome (right click save-as) and it will store all resources (images, css, js) required to fully load the page offline. Other browsers will have similar options.
You can use wget to mirror a whole website for offline browsing.
of course neither of these options will handle database driven elements of your site/page.
If you want to mock a database or dynamic elements of a page offline then Google Gears is probably the closest to what you are looking for but I think it was deprecated by Google last year.
如果您的用户拥有现代浏览器,请尝试 HTML5 应用程序缓存。
参考资料:
概述 - http://www.html5rocks.com/en/features/offline
演示 - https://jonathanstark.com/labs/app-cache-7/
教程 - https://www.html5rocks.com/en/tutorials/appcache /beginner/
文章 - http://grinninggecko。 com/developing-cross-platform-html5-offline-app-1/
If your users have modern browsers, try HTML5 Application Cache.
References:
Overview - http://www.html5rocks.com/en/features/offline
Demo - https://jonathanstark.com/labs/app-cache-7/
Tutorial - https://www.html5rocks.com/en/tutorials/appcache/beginner/
Article - http://grinninggecko.com/developing-cross-platform-html5-offline-app-1/
查看其他答案中链接的网站,大多数方法已被弃用。
现在让网站离线可用的最佳(受支持)选项是 Service Workers,所有主流浏览器均支持。您可能还想研究 PWA(渐进式网络应用程序),它有一些方法允许离线操作,包括 缓存存储 API、IndexedDB (对于二进制数据),或 WebStorage (用于存储键/值字符串对)。
Checking out websites linked in other answers, a majority of the methods are deprecated.
The best (supported) option to make a website available offline now are Service Workers, with support in all major browsers. You might also want to look into PWAs (progressive web apps), which have some methods to allow for offline operation, including APIs like the Cache Storage API, IndexedDB (for binary data), or WebStorage (to store key/value string pairs).