7

we're looking to compress our gargantuan JavaScript files with GZip to speed up the page loads of our site. I know this can be done through IIS, but I can't seem to find a simple step-by-step guide on how to implement it.

If someone could point me towards such a guide, I'd really appreciate it. I've never done this before, so it would need to be quite basic.

We're running IIS7.5 on Windows Server 2008 R2.

Your time is much appreciated.

Chuck Le Butt
  • 47,570
  • 62
  • 203
  • 289

3 Answers3

9

Turns out it's really easy:

  1. Go into IIS Manager
  2. Go to the site in question
  3. Go to 'Compression' (under IIS) and double-click on it
  4. Ensure that 'Enable static compression' is enabled.

Simple as that!

The only issues come with dynamically generated content, but I'm not interested in compressing that, so this is my answer. (Can't believe it was so easy... the other guides made it look like a nightmare!)

Chuck Le Butt
  • 47,570
  • 62
  • 203
  • 289
  • 6
    Be aware though that IIS might not serve up compressed files when you are testing due to: "You must hit the same page on IIS 7 with two different IP addresses from two different machines. If you keep trying to hit the page with the same machine it will never compress the page. Weird, but true." http://coderjournal.com/2008/04/iis-7-compress-javascript-gzip/ – Matthew Lock Apr 28 '11 at 01:51
  • @AlirezaMasali Are you trying to compress dynamic content? – Chuck Le Butt May 16 '16 at 12:30
  • @Chuck Le Butt i want that my js files not to be readable as a javascript code , – Alireza Masali May 16 '16 at 12:44
  • @AlirezaMasali Your JS files will always be readable as code, otherwise your browser could not execute them. Compression does not encrypt your JS, it compresses it with GZIP, which your browser automatically uncompresses when it receives the file. It is impossible to encrypt JS. Your best bet would be to obfuscate it with something like Uglify. – Chuck Le Butt May 16 '16 at 12:58
  • @ChuckLeButt how can i do the base 64 like this web site : http://dean.edwards.name/packer/ – Alireza Masali May 17 '16 at 05:25
  • 1
    @AlirezaMasali Try minify, or create a new question here asking how to do it. Possible interest: http://stackoverflow.com/questions/1351548/is-it-bad-to-base62-encode-a-javascript-file – Chuck Le Butt May 17 '16 at 09:46
5

'Enable static compression' didn't work for me at first.

I found that when I had these lines in my web.config file of my website between <system.webserver> it works:

<staticContent>
  <remove fileExtension=".js" />
  <mimeMap fileExtension=".js" mimeType="text/javascript" />
</staticContent>

But I have to set it in each of my web.config file and if I have a PHP website running in IIS compression is not working, also, it seems to not work for my HMTL since I get (in ySlow) :

Grade C on Compress components with gzip

There are 2 plain text components that should be sent compressed

* http://www.ville.st-augustin.qc.ca/
* http://jquery-ui.googlecode.com/svn/tags/1.8/ui/minified/jquery.effects.core.min.js
Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
VinnyG
  • 6,883
  • 7
  • 58
  • 76
2

Be sure to check that your JavaScript files are actually being compressed when you simply enable static content compression. In our scenario this was not the case. This article gives a nice overview why, Getting IIS 7 to Compress JavaScript, and in the comments @Doug Mayer recommends enabling dynamic content compression, which did work for us.

So the steps are:

  1. In IIS Manager
  2. Select the desired level, server, web application, folder
  3. Open Compression under IIS
  4. Check 'Enable dynamic content compression'
  5. Apply

If this option is greyed out, you must first add the server role service 'Dynamic Content Compression' under Web Server | Performance in Server Manager.

Liam
  • 27,717
  • 28
  • 128
  • 190
JohnC
  • 1,797
  • 1
  • 18
  • 26