homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

htaccess UTF-8 encoding for .html, .css, .js - Whats the best way?

5+ Year Member

Msg#: 4519015 posted 2:03 pm on Nov 14, 2012 (gmt 0)

For yslow page speed I want to remove my meta tag and put my encoding in the htaccess. These are all the ways I have read to do it. Which is the preferred way? Also is the language setting a good idea too? Thanks!

1) From html5 boilerplate

AddDefaultCharset utf-8
AddCharset utf-8 .html .css .js
DefaultLanguage en-US


2) from askappache

<filesMatch "\.(html|css|js)$">
AddDefaultCharset UTF-8
DefaultLanguage en-US


3) from askappache - I suspect this is all thats needed. But untested.

AddCharset UTF-8 .html .css .js
DefaultLanguage en-US



WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

Msg#: 4519015 posted 8:09 pm on Nov 14, 2012 (gmt 0)

All header-based forms have one drawback: If someone saves your page locally (yes, this might be done for legitimate reasons, not just by scrapers) the page will not contain any text encoding information of its own. So it may display incorrectly.

How much does a charset meta tag add to page loading time? Or, more exactly: does reading a header take less time than reading a meta tag?

Depending on content, your css and js may not even need to be utf-8 encoded. I've got a lurking suspicion that ascii reads faster-- but only if the browser knows ahead of time that it's ascii. (For comparison purposes, I've only got one stylesheet that contains non-ascii information. I expected to use an entity but it didn't work.*)

* Pseudo-class content. It displayed the literal entity instead of the intended non-ascii character. Oops.


5+ Year Member

Msg#: 4519015 posted 9:02 pm on Nov 14, 2012 (gmt 0)

Ya im going to keep my meta tag in my page too. For my testing purposes and as you said. Didnt think of that one. Apparently the browser is able to "look ahead" (IE8 term) and start parsing the page before it even reads it with the header info in place. Prob a 1/1000 time dif but oh well. I want that A page speed grade damnit! More reading has lead me to this code. I'm pretty certain this is all I need to serve all file extensions both rules...

AddDefaultCharset utf-8
DefaultLanguage en-US


WebmasterWorld Senior Member

Msg#: 4519015 posted 8:46 pm on Nov 26, 2012 (gmt 0)

AddDefaultCharset utf-8 in your .htaccess is the way to go if you want that 100% grade on something like yslow or google page speed. But, you also have to leave the meta version in place or your page will get an error warning of it missing when it's parsed with the W3C validator. So keeping both works -- that's what I use.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved