1

I performed the following steps:

  1. Converted javascript file to gzip file using 7-ZIP

  2. Enabled static compression in IIS

  3. Changed <script type="text/javascript" src="js/base.js"></script> to <script type="application/x-gzip" src="js/base.js.gz"></script>

Using firebug I check that base.js.gz response is empty.

Community
  • 1
  • 1
Diogo Cardoso
  • 21,637
  • 26
  • 100
  • 138
  • 2
    The type of your script should still be `text/javascript` and not `application/x-gzip`. – ThiefMaster May 03 '11 at 09:09
  • 2
    I'm not sure you can actually zip the files yourself. The compression relies on a http header (content-encoding) to tell the browser to decompress it and treat it as a regular js-file. – jishi May 03 '11 at 09:12
  • If I use `text/javascript` gives an illegal character error. – Diogo Cardoso May 03 '11 at 09:13

3 Answers3

4

That is not how you do it.

Leave your files alone and simply turn on static compression in IIS - that's it.

Sean Kinsey
  • 37,689
  • 7
  • 52
  • 71
  • How do I check if the files are really being compressed? I'm using YSlow and continues to say that the files are not compressed. – Diogo Cardoso May 03 '11 at 09:42
  • 1
    Then they aren't - simply check the HTTP-headers. There are plenty of guides available on how to enable compression eg: http://www.iis.net/ConfigReference/system.webServer/httpCompression – Sean Kinsey May 03 '11 at 09:46
2

You are both compressing the file manually, and using IIS. If you got that to work, it would be compressed twice, which the browser can't handle.

Just use the compression in IIS, it will compress the files on the fly and send the correct HTTP header so that the browser knows to decompress it.

Guffa
  • 687,336
  • 108
  • 737
  • 1,005
0

I think you need to rethink your approach. In order to enable gzipped content for static filetypes in IIS7 all you need is this in web.config:

<system.webServer>
    <httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
        <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
        <staticTypes>
            <add mimeType="text/*" enabled="true" />
            <add mimeType="application/x-javascript" enabled="true" />              
        </staticTypes>
    </httpCompression>
<system.webServer>
jishi
  • 24,126
  • 6
  • 49
  • 75