dojo and the offline application cache

我与影子孤独终老i 提交于 2020-01-05 07:06:07

问题


We've been working on an offline capable JavaScript applicaion using Dojo and the storage and offline capabilities available in newer browsers.

The application is quite large, but it seems to load the larger files from the cache, and I can see that the application is in deed cached. Were using the applicationcache features, and there are no errors in the application cache as far as I and Chrome can see.

However we run into problems. Apparently Dojo cannot load its lanugage resources, nor the SMD file that describes the service we connect to.

These problems are highly visible on webkit-mobile, which is the targeted browser.

Any ideas to what might be wrong?


回答1:


When you use off-line, (most likely mobile), most of the time you'll need an optimized build as well. You don't really want to offline a few dozen files.

I don't think XHR works offline, so any resource you load via XHR (that includes scripts, i18n bundles and other dynamically-loaded resources that are triggered via href) you should store into localStorage, and then branch off to load from loaclStorage instead of XHR when offline.

Now, you really need to be making an optimized build if you are running on the iPhone, iPad or an Android device. Also consider using the Closure Compiler to further optimize your build. See link below.

http://dojo-toolkit.33424.n3.nabble.com/file/n2636749/Using_the_Dojo_Toolkit_with_the_Closure_Compiler.pdf?by-user=t




回答2:


The issue is that dojo does a few initalization XHR Requests. It goes online to fetch its localization bundle and any .smd files for the RPC feature.

XHR cannot access the offline applicationCache, even though the bundle and smd files are avaliable there they wont be found when Dojo asks for them.

An alternative is to leave them outside the manifest file, but that means dojo wont start offline anyway.

We fixed the issue with the .smd file by adding the service specification object located in the .smd file directly to the constructor of dojo.rpc.Service. This meant that dojo had all it needed and no longer had to fetch it.

The localization bundles was different. In the end I made sure that they were appended to the end of dojo.js, letting the dojo.provide statements take care of the rest. In essence I modified the build script (a bat file for us) to after building put the compacted localization bundle at the end of dojo.js.

Now dojo can start offline.




回答3:


Have you seen this article at IBM? It seems to cover the issue you have.




回答4:


Are you using a manifest file for an HTML5 application cache? If so, you need to explicitly list files and directories to cache. Like all other resources, your built localization bundles must be accounted for in your manifest, either in the CACHE section or in the NETWORK section



来源:https://stackoverflow.com/questions/5578382/dojo-and-the-offline-application-cache

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!