Forum Moderators: not2easy

Message Too Old, No Replies

W3C validator: 'invalid content type' with gzipped css file

How can I fix this?

         

MatthewHSE

2:13 pm on Jun 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In an effort to compress my site's CSS file, I used Method 1 here [fiftyfoureleven.com]. Basically, I pasted the following code at the top of my CSS file:

<?php 
ob_start ("ob_gzhandler");
header("Content-type: text/css");
header("Cache-Control: must-revalidate");
$offset = 60 * 60 ;
$ExpStr = "Expires: " .
gmdate("D, d M Y H:i:s",
time() + $offset) . " GMT";
header($ExpStr);
?>

...then added a line to my .htaccess file so .css files would be parsed for PHP.

The compression worked great, but unfortunately the W3C CSS Validator is now giving an error when I try to validate my stylesheet. The error is "Invalid content type," but I don't understand why the error is occurring since the content-type, as you can see above, is set to text/css.

Any ideas on what might be going on here? I thought at first the validator might not properly accept compressed content, but I'm sure I've validated CSS just fine when it was compressed with mod_gzip.

Thanks,

Matthew

encyclo

2:19 pm on Jun 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What does the Page Info say when you load the CSS file directly in Firefox?

MatthewHSE

3:07 pm on Jun 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The "type" line says text/css. Actually I'd already checked that but forgot to mention it. Encoding is ISO-8859-1, although I can't imagine that that matters.

encyclo

6:39 pm on Jun 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I can't recreate this error when sending a CSS file with a .php extension. Have you tried that?

encyclo

1:02 am on Jun 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK, you've encouraged me to put gzip in place for the CSS files on one site I have where all the rest of the HTML files are already sent gzipped. I still can't reproduce the error you are seeing, though. This is how I did it:

1. In the includes directory I have added a .htaccess with the following:

AddHandler application/x-httpd-php .css

2. In the CSS file I have added your example code:

<?php
ob_start ("ob_gzhandler");
header("Content-Type: text/css");
header("Cache-Control: must-revalidate");
$offset = 60 * 60 ;
$ExpStr = "Expires: " .
gmdate("D, d M Y H:i:s",
time() + $offset) . " GMT";
header($ExpStr);
?>

Are you using the separate file for the above code and using

auto_prepend_file
or is the PHP inline? When I try the former method, the CSS is sent as
text/html
(and so is ignored by Firefox as the HTML is in standards-compliance mode), so there's a failure somewhere...

mipapage

4:52 am on Jun 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hey MatthewHSE,

I wrote that article, and can report that I have never heard of anyone else having the problem that you are having. I'd love to help out, but I'm on holidays :D If you can't get this sorted send me a sticky mail and I'll see if I can help out; there are a few little tweaks some people used, but I can't recall what they were at the moment and they are on my other machine...

MatthewHSE

12:48 pm on Jun 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for the ideas guys. After what you've said, and playing with it a bit more myself, I've about reached the conclusion that the problem I'm having is being caused by a conflict between this compression method and some other something in my .htaccess file. I'll be looking at it in more detail later today or Monday and will post back with whatever results I get.

The compression itself works great, and I'm not getting any rendering errors. The only thing is that this is for a web design site, I want the HTML and CSS validate buttons at the bottom of the page, and if the CSS won't validate it looks pretty bad! ;)

MatthewHSE

7:03 pm on Jun 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, I finally managed to get back to this, and I found the problem. It was something entirely unrelated to the compression technique; some files weren't being sent with the right headers. I've got it fixed now and the compression is really working a trick!

encyclo

7:21 pm on Jun 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Glad you got it fixed Matthew - I've been using this on my biggest site since this thread with zero reported problems. With the rest of the content gzipped as well (the pages are very markup and text content heavy) the bandwidth savings are huge.