C C
C C

Reputation: 449

is AddDefaultCharset UTF-8 in .htaccess safe?

Very long story, but I had a problem with my site, where there would be a blank white page flashed between any page/link navigation within my site. Only happened in Firefox, and only in newer versions of Firefox (e.g. didn't show up in version 3.6.x).

After comparing response headers from two different servers, the site being served from the other server was not having this problem -- I noticed that its response header had this in it:

Content-Type text/html; charset=UTF-8

My normal server which did have the problem had this in its response header:

Content-type text/html

So, I added this line to my .htaccess and the problem went away:

AddDefaultCharset UTF-8

My questions:

  1. What is it about Content-Type not having charset specified that could possibly cause Firefox to flash (like 10 millisecond) total blank white screen between pages in my site?

  2. Now that I fixed the problem, is my fix "ok"? Is it safe, or does it have some high probability of breaking something else?

My quick testing didn't show a problem, but not know knowing what side effects it could cause, or the reason why it fixed my page-flashing problem, bothers me.

Upvotes: 4

Views: 14913

Answers (1)

Jerry Tian
Jerry Tian

Reputation: 3438

I am assuming your site is mainly serving English content, and since utf-8 is compatible with most English language character encodings, I would say this method is rather safe. If not, you need to make according changes for these content.

By the way, there is also a global default character set configuration for most HTTP servers, which in theory is more efficient than .htaccess settings. And in most web applications, written by PHP, Java, whatever language it is, it should be best practice for the application itself to clearly state which encoding it is using.

For the firefox flashing part, in my past experience with browser development, the browser need to detect your encoding automatically, if it is not stated in response headers. So, if the initial assumed encoding is different with the one detected, the browser need to force the page reflow. Just a roughly guess, for the actual reason, I think the firefox mailing list should be a better place to go.

Upvotes: 3

Related Questions