JavaScript file not updating no matter what I do

前端 未结 13 732
粉色の甜心
粉色の甜心 2021-01-30 03:14

I have an external JavaScript file and whether in FireFox or Chrome, whether all browsing data is cleared, it will NOT update no matter what. I believe something happen

相关标签:
13条回答
  • 2021-01-30 03:39

    Rename your js file to something else temporarily. This is the only thing that worked for me.

    0 讨论(0)
  • 2021-01-30 03:40

    How about adding a '?2' to the tag?

    <script src="a.js?2"></script>

    The server should return the same file with or without the '?2', but the browser should see it as a different file and redownload. You can just change this query string whenever the file is changed.

    adapted from: http://blog.httpwatch.com/2007/12/10/two-simple-rules-for-http-caching/

    0 讨论(0)
  • 2021-01-30 03:40

    1.Clear browser cache in browser developer tools 2.Under Network tab – select Disable cache option 3.Restarted browser 4.Force reload Js file command+shift+R in mac   Make sure the fresh war is deployed properly on the Server side

    0 讨论(0)
  • 2021-01-30 03:46

    A little late to the party, but if you put this in your html, it will keep your website from updating the cache. It takes the website a little longer to load, but for debugging purposes i like it. Taken from this answer: How to programmatically empty browser cache?

    <meta http-equiv='cache-control' content='no-cache'>
    <meta http-equiv='expires' content='0'>
    <meta http-equiv='pragma' content='no-cache'>
    
    0 讨论(0)
  • 2021-01-30 03:46

    The best way around browsercaches is to append a random number to the path of the js file.

    Example in pseudo code:

    // generate a random number
    int i = Random.Next();
    echo "<script src='a.js?'" + i + "></script>";
    

    This will make sure your browser always reloads the file, because it thinks it's a different file because of the random number in the url.

    The server will always return the file and ignore what comes after the '?'.

    0 讨论(0)
  • 2021-01-30 03:47

    Don't forget to check any errors in webpack compilation. Sometimes the application.js in app/javascript/packs/ doesn't reload due to webpack compilation error.

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