jQuery – load a script with cache enabled

jQuery method jQuery.getScript() can be used as a shorthand to load a script given its url. This by default disables cache by appending extra random param _ (underscore) in url as shown below:


Example – jquery.ajax() load script with cache true

Here is jQuery Javascript code which can be used to load a script using jQuery .ajax() method. Note that .getScript() method also uses .ajax() method internally.

  url: 'https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?lang=css',
  dataType: 'script',
  cache: true

Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit


Click here to write/view comments