开发者

JavaScript file changes deployment

开发者 https://www.devze.com 2022-12-29 07:19 出处:网络
We are having MVC web application. Some of the code is in JavaScript. When we deploy any changes to the JavaScript, the chan开发者_高级运维ges are not reflected on the client side. We have to ask clie

We are having MVC web application. Some of the code is in JavaScript. When we deploy any changes to the JavaScript, the chan开发者_高级运维ges are not reflected on the client side. We have to ask clients to do CTRL+F5 to get the changes. Is there a standard way of pushing JavaScript changes to the client side?


You can refer to the files with a version, like this:

<script type="text/javascript" src="myScript.js?v=12345"></script>

The number after v represents your build number, so when a new build pushes, they grab the files again. View source on this page to see the same behavior :) This gives you the benefit of allowing the user to cache the files as long as possible (forever), yet still have them automatically grab any update.


you can try this meta tags

<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />


You're not saying what server-side language your site is in. A nifty trick from the Rails world is to check the "last modified" time of the file, and to add that as a GET parameter to the URL.

In PHP, it would look like this:

<script type="text/javascript" 
        src="script.js?time=<?php echo filemtime("script.js");">

(of course, the path you need to give in the filemtime call will probably need to be an absolute one.)

0

精彩评论

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