HTML5 应用程序清单未在清单更改时清除缓存
我有一个 Rails 应用程序,我正在尝试使用 Rack::Offline 来使用 HTML5 应用程序缓存。 application.manifest 文件已设置完毕,正在由我的 HTML 页面下载和检查。 清单如下所示:
CACHE MANIFEST
# 2d9bf2b03a07dc960fd8fe69659ceeffd4d28ccf8619669a506c3682bf223878
404.html
422.html
500.html
login.html
stylesheets/scaffold.css
javascripts/jquery.min.js
javascripts/jquery.js
javascripts/application.js
javascripts/rmbz.js
javascripts/rails.js
images/rails.png
NETWORK:
/
我正在访问的页面是 localhost:3000/mobile,并且它的缓存效果非常好(当我关闭 Rails 服务器时可以查看)。但是,它引用的 application.manifest 文件已更改(实际上,它通过操作注释的十六进制 id 随每个请求而更改),但 Chrome 并未更新页面。 Chrome 中的控制台日志显示以下内容:
Document was loaded from Application Cache with manifest http://localhost:3000/application.manifest
Application Cache Checking event
Application Cache Downloading event
Application Cache Progress event (0 of 12) http://localhost:3000/login.html
Application Cache Progress event (1 of 12) http://localhost:3000/404.html
Application Cache Progress event (2 of 12) http://localhost:3000/422.html
Application Cache Progress event (3 of 12) http://localhost:3000/javascripts/rails.js
Application Cache Progress event (4 of 12) http://localhost:3000/javascripts/rmbz.js
Application Cache Progress event (5 of 12) http://localhost:3000/images/rails.png
Application Cache Progress event (6 of 12) http://localhost:3000/500.html
Application Cache Progress event (7 of 12) http://localhost:3000/javascripts/jquery.js
Application Cache Progress event (8 of 12) http://localhost:3000/stylesheets/scaffold.css
Application Cache Progress event (9 of 12) http://localhost:3000/javascripts/jquery.min.js
Application Cache Progress event (10 of 12) http://localhost:3000/mobile
Application Cache Progress event (11 of 12) http://localhost:3000/javascripts/application.js
Application Cache Error event: Manifest changed during update, scheduling retry
我不太明白为什么失败。直到最后一行,它似乎已经做了所有应该做的事情!如果我在浏览器中导航到 localhost:3000/application.manifest,我会得到类似的日志 - 清单似乎已自行缓存,所以这可能就是它抱怨清单已更改的原因吗?有什么想法吗?
谢谢!
I have a rails app that I'm trying to get using HTML5 application caching using Rack::Offline. The application.manifest file is set up and is being downloaded and checked by my HTML page.
The manifest looks as follows:
CACHE MANIFEST
# 2d9bf2b03a07dc960fd8fe69659ceeffd4d28ccf8619669a506c3682bf223878
404.html
422.html
500.html
login.html
stylesheets/scaffold.css
javascripts/jquery.min.js
javascripts/jquery.js
javascripts/application.js
javascripts/rmbz.js
javascripts/rails.js
images/rails.png
NETWORK:
/
The page I'm accessing is localhost:3000/mobile, and it has cached wonderfully (viewable when I take down the rails server). However, the application.manifest file that it references has changed (in fact it changes with each request by manipulating the commented hexadecimal id), but Chrome is not updating the page. The console log in Chrome gives the following:
Document was loaded from Application Cache with manifest http://localhost:3000/application.manifest
Application Cache Checking event
Application Cache Downloading event
Application Cache Progress event (0 of 12) http://localhost:3000/login.html
Application Cache Progress event (1 of 12) http://localhost:3000/404.html
Application Cache Progress event (2 of 12) http://localhost:3000/422.html
Application Cache Progress event (3 of 12) http://localhost:3000/javascripts/rails.js
Application Cache Progress event (4 of 12) http://localhost:3000/javascripts/rmbz.js
Application Cache Progress event (5 of 12) http://localhost:3000/images/rails.png
Application Cache Progress event (6 of 12) http://localhost:3000/500.html
Application Cache Progress event (7 of 12) http://localhost:3000/javascripts/jquery.js
Application Cache Progress event (8 of 12) http://localhost:3000/stylesheets/scaffold.css
Application Cache Progress event (9 of 12) http://localhost:3000/javascripts/jquery.min.js
Application Cache Progress event (10 of 12) http://localhost:3000/mobile
Application Cache Progress event (11 of 12) http://localhost:3000/javascripts/application.js
Application Cache Error event: Manifest changed during update, scheduling retry
I don't quite understand why it's failing. It seems to be doing everything it should until the last line! I get a similar log if I navigate in my browser to localhost:3000/application.manifest - it seems that the manifest is cached itself, so could that be why it complains that the manifest has changed? Any ideas?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
Chrome 请求的最后一个文件是
application.manifest
,如果自原始请求以来该文件已更改(如您所说),则会使缓存失效。您需要保持清单不变,直到清单中列出的文件之一发生更改。The last file requested by Chrome is
application.manifest
, if this has changed since the original request (as you say it has) then that invalidates the cache. You need to keep the manifest unchanged until one of the files listed in the manifest has changed.每次在 Rails 开发模式下都会发生这种情况,因为默认情况下每次点击页面时都会重新生成密钥。您可以通过在
environments/development.rb
中将cache_classes
设置为true
来解决此问题。但请注意,cache_classes
并非特定于Rack::Offline
。因此,如果您确实进行了更改,您的开发环境中可能会出现一些意外的ActiveRecord
行为。This happens in Rails development mode every time because by default the key is regenerated every time the page is hit. You can get around this by setting
cache_classes
totrue
inenvironments/development.rb
. However, be warned thatcache_classes
is not specific toRack::Offline
. So you may get some unexpectedActiveRecord
behavior in your development environment, if you do make the change.我遇到了同样的问题,必须对宝石本身进行更改。我的问题与 /public/images 中的嵌套文件夹有关,
首先找到您的 gems 的安装位置(“gem 环境”将帮助您找到)并导航到 /rack-offline-0.6.1/lib。
编辑文件rack-offline.rb。删除第 33 行并替换为:
重新启动 Rails 服务器并重试。为我工作,希望对你有帮助。
I was having the same problem, had to make a change to the gem itself. My problem had to do with nested folders in /public/images
Start by finding where your gems are installed ("gem environment" will get you that) and navigate into /rack-offline-0.6.1/lib.
Edit the file rack-offline.rb. Delete line 33 and replace with :
Restart your rails server and try again. Worked for me, hope it helps you.
查看 http://railscasts.com/episodes/247-offline-apps-part -1 和 http://railscasts.com/episodes/248- Offline-apps-part-2
它解释了与缓存、离线、rails / jquery 等相关的所有问题。
check out http://railscasts.com/episodes/247-offline-apps-part-1 and http://railscasts.com/episodes/248-offline-apps-part-2
it explains all the issues involved with caching, offline, rails / jquery etc..
Rack::Offline 似乎使用时间窗口来刷新清单文件中的哈希值 (lib/rack/offline.rb:84)。
浏览器会请求清单文件两次:一次在请求开始时,一次所有缓存已成功离线存储。
当处理您的请求需要相当长的时间(必须加载大量资源)时,可能会出现第一个请求在一个时间窗口内得到答复而最终请求在另一个时间窗口内处理的情况。因此,两个清单中的哈希值将不匹配,并且您会收到“应用程序缓存错误事件:更新期间清单已更改,计划重试”错误。
为了减少开发过程中出现此类错误的可能性,您可以选择设置更大的cache_interval,如下所示:
Rack::Offline seems to be using a time window for refreshing the hash in the manifest file (lib/rack/offline.rb:84).
The manifest file is requested twice by the browser: once at the beginning of the request and once all cache was successfully stored offline.
When handling your request takes considerable time (lots of assets have to be loaded) it can happen that the first request is answered in one time window and the final request is handled in another. As a consequence the hashes in both manifests will not match and you get the "Application Cache Error event: Manifest changed during update, scheduling retry" error as a result.
In order to diminish the odds of such an error during development you can choose to set a greater cache_interval as follows: