How to force IE to reload javascript?

后端 未结 10 1366
清酒与你
清酒与你 2020-12-12 20:41

I\'m using IE 8 on Vista, and everytime I change a javascript file and then start debugging, I have to hit Ctrl+F5 to have it reload my javascript. Is there any way to make

相关标签:
10条回答
  • 2020-12-12 21:22

    Add a date of modification of js file at the end of your URL. With PHP it would look something like this:

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

    When your script will be reloaded every time you update it.

    0 讨论(0)
  • 2020-12-12 21:26

    If you are looking to just do this on YOUR browser (a.k.a. not forcing this on your users), then I would NOT set your code to not utilize the cache. As José said, there is a performance loss.

    And I wouldn't turn off caching on IE altogether, because you lose that performance gain for every website you visit. You can tell IE to always refresh from the server for a specific site or browsing session:

    1. Open IE Developer Tools
    2. Choose Cache from the Menu
    3. Click to check "Always Refresh From Server"

    Or, for the keyboard-shortcut-philes (like myself) out there..

    • F12, Alt+C, Down Arrow, Alt+R.

    NOTE OF CAUTION : Having said this... Keep in mind that anytime you develop/test in a different way than the site will be viewed in production, you run the risk of getting mixed results. A good example is this caching issue. We found an issue where IE was caching our Ajax calls and not updating results from a GET method. If we HAD disabled caching in IE, we would have never seen this problem in development, and would have deployed it to production like this.

    0 讨论(0)
  • 2020-12-12 21:31

    If you are running ASP.Net, check out the Bundling and Minification module available in ASP.Net 4.5.

    http://www.asp.net/mvc/tutorials/mvc-4/bundling-and-minification

    You can declare a "bundle" that points to your javascript file. Every time your file changes, it will generate a new querystring suffix... but will only do so when the file changes. This makes it super simple to deploy updates, because you don't even have to think about updating your tags with new version numbers.

    It can also bundle multiple .js files together into one file, and minify them, all in one step. Ditto for css.

    0 讨论(0)
  • 2020-12-12 21:35

    If you are in IE11, you can tell IE to always refresh from the server for a specific browsing session with IE Developer Tools.

    • Open IE Developer Tools with F12 key
    • Go to Network tab
    • Click on button "always refresh from the server"

    (Sorry for french capture)

    0 讨论(0)
提交回复
热议问题