Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is jQuery modular? How to trim it down?

Compressed, jQuery is ~70KB in size (uncompressed: >200KB). I did not see a way to exclude rarely used parts of it like with jQuery UI. How can I reduce the (compressed and minified) file size of jQuery? I am quite concerned because dial-up lines and slow machines/browsers are very common among users of my site.

My main concern is parsing duration of the JavaScript in the browser. On older machines this takes hundreds of milliseconds. The network transfer is a one-time cost which makes this slightly more tolerable.

like image 591
usr Avatar asked May 25 '10 15:05

usr


1 Answers

There is no service (such as for JQuery UI) where you can pick and choose functionality. But to help:

  1. The minified version is less than 25k, which helps. The non-minified version should never really go down to the client machine.
  2. Always reference it from the same location, and the client browser should cache it.
  3. You can reference your javascript libraries after your html content, so that initial load should seem faster to the human.
  4. reference your jquery library from a different domain than yours, like from google. There are several advantages to this:
    • It is likely to get served form a location closer to your clients
    • It increases the chance that it will be download in parallel to other resources, especially with older browsers that will only download 2 items from a domain at a time.
    • It increases the chance that they won't have to load jQuery at all for your page, because it's already cached from this commonly-used site.
like image 89
Patrick Karcher Avatar answered Oct 01 '22 21:10

Patrick Karcher