How to append timestamp to the javascript file in [removed] tag url to avoid caching

前端 未结 8 1754
[愿得一人]
[愿得一人] 2020-11-28 08:21

I want to append a random number or a timestamp at the end of the javascript file source path in so that every time the page reloads it should download a fresh copy.

<
相关标签:
8条回答
  • 2020-11-28 09:17

    Replace regular expression if not alphanumeric Date.prototype.toISOString()

    var today = new Date();
    "MyFile_" + today.toISOString().replace(/[^\w]/g, "") + ".pdf"
    

    MyFile_20191021T173426146Z.pdf

    0 讨论(0)
  • 2020-11-28 09:27

    Load scripts manually or with jQuery http://api.jquery.com/jQuery.getScript/. It also provides option to prevent chaching

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