Search code examples
javascriptminifyuglifyjs

Filesize of Javascript is different by its location, local or server


I have made a web application and I realized that the corresponding filesize of the application`s bundled javascript is slightly more than 1mb. (I have used react and webpack, so only one javascript exists on client side) Of course I did minification to reduce the size of the javascript file which was originally 3mb.

However, today I found out somewhat amazing phenomenon. The detailed description of it is as follows: If I get a script of jQuery through Google`s CDN, the filesize of it is about 33kb. However if I copy and paste the file into my local server, the filesize of it is roughly 90kb which is almost 3-times amount of the original one, though the two are logically same thing.

I think that it can be a clue to reduce the size of javascript file. I tried to write down as thoroughly as possible, but if my description is too abstract, please ask me additional information. Thank you in advance.


Solution

  • It's likely that you're seeing the gzipped file size - gzip is a common file compression used to transmit data over HTTP. When the file is decoded it will be larger, but your browser will show the pre-decompression file size.

    Using this tool with https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js shows me that the original size of the jQuery file is 86,000 bytes but compressed it's only 30,000 bytes.