Since the update to Mac OS Mavericks all my styles and scripts get served as text/html
I have no idea where I can change this behavior. I'm using the built in apache service
EDIT: I forgot to mention that static files works as expected. The files above get parsed by a php script to get served cached and compressed. I'm using header("Content-type: text/css") to define the content type
In your server/vhost config try adding:
AddType text/javascript .js
AddType text/css .css
If something else is already setting the type, you can try adding this instead:
<Files "*.js">
ForceType text/javascript
</Files>
<Files "*.css">
ForceType text/css
</Files>
After further digging into the cacheing script I found a flush() method forces PHP to add a text/html content type in the header. This happens right before I add headers like header("Content-type: text/css")
I've rewritten my class method and the output is now correct. Strange is that it doesn't cause the problem on my live server with the same cacheing class
Related
We have mutiple files where we need to set MIME type based upon file type. Ex:
/{path}/alpha.woff --> font/woff
/{path}/beta.woff2 --> font/woff2
/{path}/gamma.ttf --> font/ttf
We have added the below snippet in apache config file but not certain how to achieve with one LocationMatch attribute
<LocationMatch "\.(?i:woff|woff2|ttf)$">
Header set Content-Type font/{dynamically set woff OR woff2 OR ttf }
</LocationMatch>
This can be done with multiple LocationMatch (one for each font) but looks not optimized one.
Can anyone suggest better solution to deal with such situation?
Tried with regex which throw an error.
<LocationMatch "\.(?<fonttype>(?i:woff|woff2|ttf))$">
Header set Content-Type font/woff // Work fine but set font/woff for all fonts
</LocationMatch>
Below throw error in config
<LocationMatch "\.(?<fonttype>(?i:woff|woff2|ttf))$">
Header set Content-Type font/%{env:MATCH_FONTTYPE}
</LocationMatch>
Unrecognized header format %
The mime types can be configured in the conf/mime.types configuration file of the Apache HTTP Server, see the example here:
font/woff woff
font/woff2 woff2
font/ttf ttf
If you can't update this file, and LocationMatch directive is your only option, then starting from Apache 2.4.8 you can use named regex capture groups, see documentation.
In the following example, I've named the capture group fonttype, so by convention it will be put into the environment variable MATCH_FONTTYPE. This environment variable can be used in the ForceType expression:
<LocationMatch "\.(?<fonttype>(?i:woff|woff2|ttf))$">
ForceType font/%{env:MATCH_FONTTYPE}
</LocationMatch>
We are currently having Content-Type: text/html.
We want to modify this to text/javascript or text/css.
We have tried this using rewrite rule, mod_headers and also through mod_mime, but we are unable to modify it.
Any suggestion?
Assuming you have certain text files in a directory say styles add a .htaccess file in the root directory and add the following content:
<Location /styles>
ForceType text/css
</Location>
And use the similar concept for javascript as well
I had solved this by changing the content type in application servers of content.
When I check this website: http://www.tropicbreeze.co.uk/, for example with http://checkgzipcompression.com/ - it reports that it is using Gzip. But Yslow disagrees.
I have this in my .htaccess file:
AddOutputFilterByType DEFLATE text/html text/php text/x-php application/php application/x-php application/x-httpd-php-source text/plain text/xml text/css text/javascript application/x-javascript application/xhtml+xml application/javascript application/x-httpd-php
Checking in the Net tab of Firebug for headers, I can see that the various associated .css and .js files on that page have Content-Encoding gzip appearing as expected - but the php files do not.
Yslow tells me that the homepage is not using Gzip. The Firebug Net tab says that the home page (and other php files on the server) are not being sent with Content-Encoding gzip
I've tried adding all the mimetype filters I could find suggested, and so far as I can see, DEFLATE text/html should cover it anyway, but still no joy.
I have cleared my cache and am not using a proxy.
Can anyone suggest what I've missed? Why are the php files not being gzipped when the other files are? Or, if they are being gzipped, why does Firebug /yslow think they aren't?
Not sure exactly what the issue might be but perhaps an easy fix would be to try something like...
<IfModule mod_deflate.c>
<FilesMatch "\.(css|htm|html|js|php|txt|xml)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
...which should setup compression on popular file extensions including PHP.
I personally think this format is much easier for a human to read too. Bonus!
I have made an ,htaccess file in my /font directory with only this line in it (as part of troubleshooting).
AddType text/css .css
None the less Google Chrome (even 19.0.1053.0 canary) reports that the .css files are returned as: MIME type text/html
http://paulanorman.com/:11 Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://paulanorman.com/fonts/iwona-stylesheet.css".
I use Hostgator and have checked in Cpanel that text/css is default on my server for .css
I have also checked using wget on cygwin bash shell and the documents are indeed coming down as text/html
These stylesheets are being ignored. However I have found if I
<style ..>
<?php include "dah dha / style-sheets.css" ?>
</style>
one by one in the head of my document all is fine.
However I would like not to have to do that.
Any one solved this? I have read much all over the net about this and it appears as an unexplained fickle problem it seems.
TIA
paul
According to www.askapache.com this is ok as a one step process with the quote marks
AddType 'text/css; charset=UTF-8' css
What is the recommended way to configure Apache to enable HTTP compression for CSS and JS fiels, using .htaccess? I have seen several different directives used in examples on the web. I have tried some of these and yet I have not been able to get it to work. I am checking the HTTP headers using Firebug.
Ensure that mod_deflate and mod_mime are enabled and add something like:
AddOutputFilterByType DEFLATE application/x-javascript text/javascript text/css
to your .htaccess.
See also: http://brightscape.net/blog/compress-your-web-pages-with-mod_deflate/