Cache files with jQuery and ajax method


/ Published in: jQuery
Save to your folder(s)

Handy little snippet i found in 'jquery enlightenment' for caching certain selected files. Could be useful for larger files later on in a site.


Copy this code and paste it in your HTML
  1. (function($){
  2. $(window).load(function(){
  3. //Wait for the page to load, the cache the files you want
  4. $.ajax({url:'javascript.js', dataType:'text'});
  5. $.ajax({url:'image.jpg', dataType:'text'});
  6. $.ajax({url:'flash.swf', dataType:'text'});
  7. $.ajax({url:'style.css', dataType:'text'});
  8. });
  9. })(jQuery);

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.