7

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.

usr
  • 168,620
  • 35
  • 240
  • 369

7 Answers7

17

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.
Patrick Karcher
  • 22,995
  • 5
  • 52
  • 66
5

You can also let Google host jQuery for you, which gives you better caching, etc.

Robusto
  • 31,447
  • 8
  • 56
  • 77
2

There is a jQuery builder which you can use to trim some parts of jQuery.

niutech
  • 28,923
  • 15
  • 96
  • 106
2

24kb minimized and gzipped are not worth the effort IMHO.

jAndy
  • 231,737
  • 57
  • 305
  • 359
1

Can't tell exactly when the change was made, but the JQuery team now allow developers to compile their own JQuery builds using Node JS. NPM (which is effectively part of Node now), and Grunt are perquisites.

The custom build process appears to allow developers to exclude key components like the .Ajax and .Effects modules.

Details can be found in the JQuery github project readme file.

https://github.com/jquery/jquery

Charlie
  • 4,197
  • 5
  • 42
  • 59
1

The minified version is 24kb minified and gzipped. jQuery UI is bundled seperately and it is modular and has a packager which allows you to choose which parts of jQuery UI you want included.

If you reference it from the google or microsoft CDN's then it will also get cached in the browser, for not just your site, but any site that uses the CDN.

lomaxx
  • 113,627
  • 57
  • 144
  • 179
0

jQuery is not modular. Even with dial up I don't think 24kb is a big deal.

Laplace
  • 491
  • 1
  • 3
  • 9