本文介绍了在本地存储中存储CSS和JS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的webapp主要用于手机上,所以我正在寻找存储静态CSS和JS文件,以减少加载时间。



虽然我知道获取和设置值很容易:

  //将对象放入存储
localStorage.setItem('testObject',JSON.stringify(testObject));

//从存储中检索对象
var retrievedObject = localStorage.getItem('testObject');

...但我不知道如何设置,获取和渲染/执行CSS样式表和Javascript文件。任何例子都会有帮助。

解决方案

也许你正在寻找的appCache下载你的文件的源文件一次,只检查appcache文件是否修改,


$ b / p>

 < html manifest =myfile.appcache> 

在您的项目根文件夹中创建appcache文件:myfile.appcache / p>

  CACHE MANIFEST 
#列出所有文件

网络:
*

有关详情,请参阅官方文档:



来自html5rocks的好解释:


My webapp is primarily used on mobiles so I'm looking to store static CSS and JS files to reduce the loading time. Its a trick even Google and Bing seems to use I read somewhere.

Although I understand getting and setting values is easy:

// Put the object into storage
localStorage.setItem('testObject', JSON.stringify(testObject));

// Retrieve the object from storage
var retrievedObject = localStorage.getItem('testObject');

... but I'm not sure how I could set, get and render/execute CSS stylesheets and Javascript files. Any example would help.

解决方案

maybe you are looking for appCache which download the source of your files once and checks only if appcache file is modified to update your source.

This is really simple to implement.

update your html

<html manifest="myfile.appcache">

Create your appcache file: myfile.appcache in your project root folder

CACHE MANIFEST
# LIST ALL YOUR FILES 

NETWORK: 
*

See official doc for more info : http://www.w3schools.com/html/html5_app_cache.asp

Good explanation from html5rocks : http://www.html5rocks.com/en/tutorials/appcache/beginner/

这篇关于在本地存储中存储CSS和JS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 01:04