2

I have a new VPS Host and have cloned my existing live site from my current VPS Host. On the new host, there is an issue with JS aggregation and I am hoping someone might recognize what this is and how to solve it.

Generally with JS aggregation set at /admin/config/development/performance, Javascript breaks sitewide, both front end and backend, logged in and non-logged in. I checked permissions and the JS directiory at /sites/default/files/js/ and it seems fine, files are writing to this directory (both the JS files and the GZipped ones).

When I view the raw code of any of these files, the code is fine (not corrupt). I have also tried switching this off, clearing cache, switching back on, clearing browser cache and even deleting the directory which Drupal did and then recreated without any issue. I checked my PHP info file (5.2.17) and it shows this under PHP Variables _SERVER["HTTP_ACCEPT_ENCODING"] - gzip,deflate,sdch so that seems ok. However my old server's PHP info file also had gzip,deflate,sdch under an additional heading called "HTTP Headers Information".

But here is the real tell-tale, I think, when I view the code of my webpage with Chrome web inspector and look in Console, I see as many JS errors as there are aggregated files. (5 or 6 I think). The error is: Uncaught SyntaxError: Unexpected token ILLEGAL If I then view the corresponding JS file, I see this:

enter image description here

So somehow, the aggregated JS files are turning into gibberish characters and the errors are thrown. I have spoken with my webhost and we tried some things but nothing worked. They had me put this code into .htaccess but it did not work:

[root@host ~]# httpd -L | grep deflate
DeflateFilterNote (mod_deflate.c)
DeflateWindowSize (mod_deflate.c)
DeflateBufferSize (mod_deflate.c)
DeflateMemLevel (mod_deflate.c)
DeflateCompressionLevel (mod_deflate.c)

Also I was not exactly sure where in .htaccess to put it. (under <IfModule mod_headers.c> perhaps?) At any rate this did nothing to help matters no matter where I tried that code. I feel like this is a bit of a needle in a haystack and might be tricky to fix but I am curious if anyone recognizes what might be going on so i can fix it.

** I should also note that litespeed Server is running on top of this so not sure if there are nay issues with that. I have not looked into this yet.

3
  • 1
    Do you have an uncommented line like AddType application/x-gzip .gz .tgz or AddEncoding x-gzip .gz .tgz in your httpd.conf file?
    – Clive
    Jun 25, 2012 at 23:39
  • Clive, Brilliant. That works. I also found a core issue here: drupal.org/node/1440534 but that did not actually fix my issue, however your code did. If you want to add this as an answer, I will accept and vote up. Thanks! Jun 25, 2012 at 23:44
  • Will do, glad it helped I remember that happening to me some time back
    – Clive
    Jun 25, 2012 at 23:45

1 Answer 1

5

It's likely that your web server isn't sending the correct Content-Type or Content-Encoding header for compressed files.

Adding one of these to your httpd.conf file should solve the problem:

AddType application/x-gzip .gz .tgz

or

AddEncoding x-gzip .gz .tgz

There should be comments in your httpd.conf file that will help you determine which one's most appropriate for your situation (search for <IfModule mime_module> in that file if you're interested).

2
  • After thorough testing, this works great in all browsers except Chrome Canary. Chrome Production works fine. In Canary, I get this error on CSS files now: Error 330 (net::ERR_CONTENT_DECODING_FAILED): Unknown error. A google search yielded a few forum posts with lots of different suggestions and explanations. productforums.google.com/forum/#!topic/chrome/vxIgSHj3CGg Jun 26, 2012 at 2:00
  • Update, it seems like I needed to add more resources to litespeed and I now have JS and CSS aggregation working in all browsers, however, I still cannot get JS gzip working. See drupal.org/node/1440534 Jun 26, 2012 at 20:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.