web项目js css静态文件缓存解决_html/css_WEB-ITnose
基于grunt的js 及css文件自动加version的插件,可以将配置的目录下所有引用到指定匹配的js及css文件加上一个版本号
github地址: https://github.com/noahxinhao/automatic-version-increment
具体的说明
control the cache of assets by appending timestamp hash to asset url
Getting Started
This plugin requires Grunt ~0.4.1
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install automatic-version-increment --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('automatic-version-increment');
The "automatic" task
Overview
In your project's Gruntfile, add a section named automatic to the data object passed intogrunt.initConfig().
grunt.initConfig({ automatic: { js: { options: { }, assetUrl:'demo/js/hello.js', files: { 'tmp': ['demo/index.html'], }, }, },});
Usage Examples
Default Options
In this example, we have index.html which contains hello.js and hello.css. In Gruntfile.js, write as below, then grunt, we can get the index.html which has assets url with timestamp.
assetUrl is the css or js file path files is the file which contains the assets(usually is html file)
Notice to write the correct path.
grunt.initConfig({ automatic: { js: { options: { basicSrc: ["src/main/webapp/public/js_control/"] }, assetUrl: ['**/*.js'], files: { 'tmp': ['src/main/webapp/views/**/*.jsp'] } }, css: { options: { basicSrc: ["src/main/webapp/public/css/"] }, assetUrl: ['**/*.css'], files: { 'tmp': ['src/main/webapp/views/**/*.jsp'] } } }});
Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
上一篇: php 图片地址和删除网址部份正则方法_PHP教程
下一篇: html ol标签怎么用
推荐阅读
-
web项目js css静态文件缓存解决_html/css_WEB-ITnose
-
关于两个div高度保持一致的(css+js)两种解决办法_html/css_WEB-ITnose
-
静态网页 包含css 直接打开文件没问题,但是部署到IIS后访问不正常_html/css_WEB-ITnose
-
一个带参数的URL指向一个静态文件后面的参数有没有作用?_html/css_WEB-ITnose
-
jquery语句写在页面中正常执行,放到JS文件里面就执行不了_html/css_WEB-ITnose
-
我有二个CSS文件,根据不同屏幕,使用JS如何来控制它导入呢?_html/css_WEB-ITnose
-
ajax加载html文件并执行其中的js代码,加载css样式_html/css_WEB-ITnose
-
如何解决因为缓存无法及时更新图片问题_html/css_WEB-ITnose
-
chm文件转换成html文件,解决chm文件无法使用浏览器打开的问题_html/css_WEB-ITnose
-
Android Webview 加载外部html时选择加载本地的js,css等资源文件_html/css_WEB-ITnose