开发者

refresh html js page

开发者 https://www.devze.com 2023-02-08 06:52 出处:网络
<script type=\"text/javascript\" src=\"main.js\"></script> If This is in the my header page and which is included in all pages.My question is that when there are any changes in main.js t
<script type="text/javascript" src="main.js"></script>

If This is in the my header page and which is included in all pages.My question is that when there are any changes in main.js the user has to refresh his browsers cache.开发者_运维知识库So instead of this if we use

<script type="text/javascript" src="main.js?1"></script>

user would get latest changes without refreshing the cache.If again a change ismade in main.js change has to be made like

<script type="text/javascript" src="main.js?sumnumber"></script>

My question is that is there any generic way to do this


You can use Date.geTime() or some such which returns the ticks, it's a common way to cache bust.

However, generating the tags will be more of a pain.

You can of course turn of caching on the web server side so that your page shouldn't be cached.


You can let your Version Control System put in a version number whenever you check-in your source code.

e.g in CVS you can use the $Revision$ keyword:

<script type="text/javascript" src="myfile.js?$Revision$"></script>


if you are looking for every request from the same browser to force re-download, then you want the url to change every time, e.g.

<script type="text/javascript">
   document.write('<script type="text/javascript" src="main.js?' +Math.random()+ '"></script>');
</script>
0

精彩评论

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