Liron Harel
Liron Harel

Reputation: 11247

Unexpected token ILLEGAL with gzip compression

I am having a problem with gzip compression on my site. I've combined several javascript files to one files and they work ok without compression. Afterwards I've compressed them (gzip) and tried to run the site again, but get the following error:

Uncaught SyntaxError: Unexpected token ILLEGAL

I've compressed the file using several methods, one using gzip software and I also tried other gzip online compression tools like this one.

I can't understand why I get this error why it doesn't work, because the non-compressed version does work. I ran the site on Chrome, latest version.

It also tells me that the error is in line 1

all_js.js.gz:1

Of course the compressed code has many lines, not just one.

I've read a few answers, but nothing regarding gzip compression.

I get this error when working with Visual Studio (ASP.NET) on local machine.

I tried serving the file from S3 with 'application/x-gzip' headers, but it still didn't work. I want to serve my files via CDN after compressing, so I don't search for server compression solutions.

Upvotes: 3

Views: 2819

Answers (1)

arjenve
arjenve

Reputation: 2333

You cannot compress a javascript file with gzip or any other zip routine and load it into your webpage.

You can do one of two things:

  • Use a javascript code compression tool like the YUI compressor.
  • Configure your webserver to compress the files (please read the documentation of your webserver, it should not be very difficult)

Upvotes: -8

Related Questions