Reputation: 11
I'm developing a Javascript based "bookmarklet" that lets you find and bookmark images on a website. The loading speed of it is very important but because of ongoing improvements to the Javascript I'ld like to avoid long time caching.
Is it possible to allow caching just for 24 hours and after that time the latest Javascript get loaded? This is my current code:
javascript:(function(){
new_script=document.createElement('SCRIPT');
new_script.type='text/javascript';
new_script.src='http://example.com/js/bookmarklet.js?x=' +(Math.random());
document.getElementsByTagName('head')[0].appendChild(new_script);
})();
Thanks for your tips.
Upvotes: 1
Views: 139
Reputation: 5505
Read this article:
http://www.quirksmode.org/js/cookies.html
By using cookies you can set cookie for 24hours (1 day) as per your requirement.
Hope this will be helpful!
Upvotes: 0
Reputation: 5644
You could simply add the timestamp of the last edit of your javascript to the include src.
<script type="text/javascript" src="myscript.js?TIMESTAMP_OF_EDIT"></script>
That way it should be reloaded every time you edit the script.
Upvotes: 1