本文介绍了您可以在localStorage中存储JavaScript和CSS文件,以提高在线Web应用程序的性能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Web应用程序,它的行为非常类似于iOS和Android的本机应用程序。然而,Javascript文件(jQuery +我自己的)和css文件一起用于移动使用,如果用户没有启用3G,这会使应用程序加载缓慢。

I'm working on a web application, which acts pretty much like a native application for both iOS and Android. However the Javascript files (jQuery + my own) and the css file together are pretty large for mobile use, which make the app slow to load if the user doesn't have 3G enabled.

因此我开始考虑离线存储这些文件。然而,除了cache.manifest(据我所知,只有在没有互联网连接以启用离线使用时才开始),我找不到这个。理想情况下,我想检查文件是否已经缓存/存储,如果没有,请使用它们,然后再存储它们。

I therefore started to think about storing these files offline. However aside from the cache.manifest (which in my knowledge only kicks in when there is no internet connection to enable offline use) I have found no way to this. What I ideally would like to have is to check if the files are already cached/stored and if not, use them and then store them for the next time.

这是可能?这将减少加载我的应用程序的时间,因为索引文件本身非常小。我仍在努力通过优化减少文件,但在此期间这将有很大帮助。

Is this possible? This would reduce the time to load my app a lot as the index file itself is very small. I'm still working on slimming down the files by optimizing but this would help a lot in the meantime.

只是提供更多细节,对不起,如果我之前不清楚。

Just to provide a bit more detail, sorry if I was unclear before.

我已经开始使用HTML5样板和我的.htaccess构建这个webapp了file有所有JS和CSS文件头,有效期为1年。

I've started building this webapp using the HTML5 boilerplate, and my .htaccess file has all JS and CSS file headers with an expiration date of 1 year.

但似乎从iOS主屏幕打开应用程序会加载.js和.css每次都有文件,就像没有缓存它们的情况一样。在桌面或甚至iOS Safari Web浏览器上打开网站似乎确实以正确的方式缓存文件,因为Javascript和CSS中的更改仅在手动刷新页面后显示。

But it seems that opening the app from the iOS Home Screen loads the .js and .css files each time, as was the case for when they are not cached. Opening the website on a desktop or even the iOS Safari web browser does seem to cache the files the right way, as changes in the Javascript and CSS are only displayed after manually refreshing the page.

似乎打开和关闭并从主屏幕打开web-app充当刷新,因此每次加载文件,即使它们通过cache.manifest存储以供离线使用,以及文件'到期日期远远落后于未来。

It seems like opening and closing and opening the web-app from the home screen is acting as a refresh, therefore loading the files each time, even though they are stored through a cache.manifest for offline use, and the files' expiration dates are set far into the future.

以为我会为文件添加缓存头。这些似乎没问题。

Thought I'd include cache headers for the files. These seem to be alright.

Cache-Control max-age = 31536000,public

Expires Fri,18 May 2012 17:34:20 GMT

改变接受编码,用户代理

内容编码gzip保持活动超时= 2,最大= 98

Cache-Control max-age=31536000, public
Expires Fri, 18 May 2012 17:34:20 GMT
Vary Accept-Encoding,User-Agent
Content-Encoding gzip Keep-Alive timeout=2, max=98

推荐答案

您应该调查此选项:

这篇关于您可以在localStorage中存储JavaScript和CSS文件,以提高在线Web应用程序的性能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 18:37