简体   繁体   English

强迫RequireJS文字!重装

[英]forcing RequireJS text! to reload

Using the text! 使用文字! plugin, is there a way of forcing RequireJS to reload a file rather than returning the cached data? 插件,有没有办法强制RequireJS重新加载文件而不是返回缓存的数据?

RequireJS will only cache the file per request. RequireJS只会按请求缓存文件。 A page reload will fetch it again. 页面重新加载将再次获取它。 If you see something different it is because: 如果你看到不同的东西,那是因为:

  • Either you have caching on your server. 要么在服务器上进行缓存。
  • or your browser caches the request. 或者您的浏览器缓存请求。 You can of course disable this on your browser. 您当然可以在浏览器上禁用此功能。

If you want browsers to fetch a clean file every time, you should have a no-cache header for these resources on your server. 如果您希望浏览器每次都获取一个干净的文件,那么您的服务器上的这些资源应该有一个no-cache标头。

I think that you could add the new html5 cache feature by providing a cache manifest: http://www.html5rocks.com/en/tutorials/appcache/beginner/ 我认为您可以通过提供缓存清单来添加新的html5缓存功能: http//www.html5rocks.com/en/tutorials/appcache/beginner/

then you could use the requirejs "domReady" to get the proper load event: http://requirejs.org/docs/api.html#pageload 然后你可以使用requirejs“domReady”来获得正确的加载事件: http ://requirejs.org/docs/api.html#pageload

and then listen to the proper event (code taken from the first link): 然后听取正确的事件(从第一个链接获取的代码):

window.applicationCache.addEventListener('updateready', function(e) {
if (window.applicationCache.status == window.applicationCache.UPDATEREADY) {
  // Browser downloaded a new app cache.
  if (confirm('A new version of this site is available. Load it?')) {
    window.location.reload();
  }
} else {
  // Manifest didn't changed. Nothing new to server.
}}, false);

at this point whenever you update urlArgs you will get the new js files and with the manifest cache file you will get the new html files 此时,每当您更新urlArgs时,您将获得新的js文件,并使用清单缓存文件,您将获得新的html文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM