Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to cache my javascript files to improve performance

So here is my header:

<script type="text/javascript" src="js/jquery-1.6.2.min.js"></script> 
<script type="text/javascript" src="js/jquery-ui-1.8.14.custom.min.js"></script> 
<script type="text/javascript" src="js/jdpicker/jquery.jdpicker.js"></script> 
<script type="text/javascript" src="js/uniform/jquery.uniform.min.js"></script> 
<script type="text/javascript" src="js/jquery.hotkeys.js"></script> 
<script type="text/javascript" src="js/visualize/visualize.jQuery.js"></script> 
<script type="text/javascript" src="js/jquery.cookie.js"></script> 
<script type="text/javascript" src="js/fancybox/jquery.fancybox-1.3.4.pack.js"></script> 
<script type="text/javascript" src="js/jwysiwyg/jquery.wysiwyg.js"></script> 

All of these have to be loaded and its lagging my site how can i get them cached so the load time is faster

like image 391
Tahoe Cale Avatar asked May 06 '26 12:05

Tahoe Cale


1 Answers

You've got a big load of JavaScript in your pants! My suggestions would be (please don't be offended, as I'm sure you've already taken many of these steps):

  • Make sure that you need all of these js files on the page. Are you using fancybox? Are you using cookie.js? If there are any js files that you can remove from the list, do so.
  • Are any of these js files available over CDN? jQuery is. jQuery UI is. This will reduce the load on your server, and many users may come to your site with cached versions of these js libraries already in their laps!
  • Are there any lighter versions of your libraries that you could swap out for? If so, swap 'em!
  • For those files that you're hosting locally, minify and mash them. If you're working in Visual Studio, you can use Chirpy or Combres. If you're not using Visual Studio, plenty of other cool tools are out there to help you reduce the size of your CSS and JS assets.
  • Consider using Less for CSS and CoffeeScript for JS. They'll speed up your development cycle AND they'll pre-optimize a lot of your code (if you're lucky).
  • Now that you've got one big mashed, minified, optimized JS file, you can cache it. This step is platform specific, so you might need to go searching around.

Did I miss anything crucial? Those are the quick steps that I take. I think.

like image 63
Evan Nagle Avatar answered May 09 '26 01:05

Evan Nagle



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!