Search code examples
javascriptjquerybrowser-cacheexternal-js

Disable the Cache Busting in Dynamically Linked External Javascript Files?


When loading content through AJAX which contains an externally linked Javascript file or when using jQuery.getScript() function call, the linked Javascript files are appended with a cache busting parameter, which prevents the file from being cached by the browser.

So, instead of writ­ing some­thing like <script src="/js/foo.js">, it writes some­thing like <script src="/js/foo.js?_=ts2477874287">, caus­ing the script to be loaded fresh each time.

Is there a way to disable this and have the file cached when it's loaded?


Solution

  • I don't know about getScript, but cache is a parameter you can set in a .ajax() parameter map. It's false by default for scripts but you can flip it to true. Once false, it won't append a cache-busting query string.

    [updated per comment]