paultondeur / grunt-cache-busting Goto Github PK
View Code? Open in Web Editor NEWCache busting files and updating references
Cache busting files and updating references
A package.json containing dependencies of:
"dependencies": {
"grunt": "1.0.1",
"grunt-cache-busting": "0.0.11",
...
},
Results in:
npm WARN [email protected] requires a peer of grunt@~0.4.0 but none was installed.
Great task^^
I had a minor scuffle with the template replace regex. I am using RequireJS standard script tag:
<script data-main="PATH/TO/MAIN/CACHEBUSTED/src.js" src="PATH/TO/requirejs.js"></script>
When I ran grunt-cache-busting with the following params:
replace: ['my/templates.html'],
replacement: 'src.js',
file: 'PATH/TO/MAIN/CACHEBUSTED/src.js',
cleanup: true
The regex ate my requirejs src
attr and gave me:
<script data-main="PATH/TO/MAIN/CACHEBUSTED/src-HASH.js">
The fix is simple: put src
before data-main
.
Maybe by design but, it should probably be noted somewhere if so.
I wish I could be more helpful and provide a fixed fork but I am swamped right now ใ ใ
Hi there,
I've been applying cache-busting in my grunt workflow for my styles.css file. Running the task first time round works perfectly, appending the hash to both the css file and the html file path.
However, when re-running the task after updating the css file, the file hash is appended, and the old one is cleaned up. However, the html path keeps the original hash. I suspect this is due to the search string in the 'replacement' no longer generating a hit due to the presence of the hash?
'cache-busting': {
css: {
replace: ['inc/head.php'],
replacement: '/css/styles.min.css', //no hash in search string, so no update in html?
file: 'css/styles.min.css',
cleanup: true
}
},
Is there a clean work around?
Hi guys, thanks for the plugin. Trying to use it on our site likeso:
'cache-busting': {
css: {
replace: ['<%= config.themeroot %>/Layouts/default.ctp'],
replacement: 'filename.min.css',
file: '<%= config.webroot %>/css/filename.min.css'
}
}
So it works great the first grunt, updating the path in default.ctp to 'webroot/css/filename.min-MD5-HASH.css', but every subsequent grunt the filename never changes again, guessing because the process is looking for 'filename.min.css'
Is there a wildcard or other method I could use of changing the existing filename path?
Is there a way for the cache bust to clean up after itself (i.e. delete the previously hashed file?).
v0.0.11 isn't tagged on this repo - I don't suppose you could add one for it? :-)
This was my replacement:
encoding_template: {
replace: ['public/views/includes/header.html'],
replacement: 'encoding_template.html',
file: 'public/views/includes/encoding.html'
}
This was the reference inside header.html:
<li class="dropdown" data-ng-controller="EncodingController" data-ng-include="'views/includes/encoding_template.html'" data-ng-show="currencyIsBCH"></li>
Like this, when running the encoding_template task, grunt entered an infinite loop and I had to kill it. The workaround I discovered was moving data-ng-include
to the end of the attribute list:
<li class="dropdown" data-ng-controller="EncodingController" data-ng-show="currencyIsBCH" data-ng-include="'views/includes/encoding_template.html'"></li>
This way, it works.
Example:
bust: {
replace: ['my.html'],
replacement: 'jquery.js',
file: 'somewhere/jquery.js'
}
The html
<script src="jquery/jquery.js"></script>
is being transformed to:
<script src="jquery-HASH.js"></script>
<!-- instead of -->
<script src="jquery/jquery-HASH.js"></script>
FYI, I'm not really trying to cache-bust jquery, I just chose it as an example.
I saw in the code that the extension is pretty coupled to everything else, so it wasn't straight forward to fix it.
Thanks for plugin by the way ;)
Is is possible to add an option to add the hashed file instead of writing over the file. This is creating an issue when using grunt-contrib-watch since it's looking for the original version which is overwritten.
Hello,
I use grunt-cache-busting tasks also for cache cleaning of sprite image (when I create new sprite by another task, the result is new Less file, but referencing to sprite image with no version), so I clean Less file by:
..
spritespngincss: {
replace: ['www/css/sprites/partners.less'],
replacement: 'partners.png',
file: 'www/images/sprites/partners.png',
get_param: true,
}
*But cache-busting makes changes only for first apperance in file: *
/*partners.less*/
.partners-akc {
display: block;
background-image: url(../images/sprites/partners.png?v=dd7870f2a3d830f82b7bfbad54d34fcc);
background-position: -300px -60px;
width: 150px;
height: 60px;
box-sizing: border-box;
}
.partners-apek {
display: block;
background-image: url(../images/sprites/partners.png);
background-position: -150px -285px;
width: 150px;
height: 60px;
box-sizing: border-box;
}
Is there some parameter to force replace all apperance?
Thanks,
Vaclav!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.