开发者

Javascript limited time caching

开发者 https://www.devze.com 2023-03-14 10:28 出处:网络
I\'m developing a Javascript based \"bookmarklet\" that lets you find and bookmark images on a website.

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/bookm开发者_如何学运维arklet.js?x=' +(Math.random());
document.getElementsByTagName('head')[0].appendChild(new_script);
})();

Thanks for your tips.


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.


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!

0

精彩评论

暂无评论...
验证码 换一张
取 消