I have a rather strange problem, I operate a site where some pages are in French and some are in English, thus I have the need to change main "html" tag from page to page. I (obviously) decided to do so with PHP, but it seems to affect the load time of the page. No idea why this happens, because it seems to be illogical.
Here you can see the small manipulation I make in the "lang" attribute of the "html" element. When I add it as so - my page sometimes shows blank white screen for a part of the second and then loads the page. You could say it looks like a brief white blink. I guess it doesn't do any damage, but it sure looks anoying. This ONLY happens if I try to manipulate the "html" code by PHP. I tested it with and without at least 100 times.
If I leave it static as this:
<?php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
It always loads without the blank white screen. What could be causing this? I'm testing it on localhost, firefox.
Shouldn't a page be pre-compiled by PHP on the server and then simply outputted to the browser? Is there any unknown rule that I'm not aware of? I thought it would be perfectly fine to make such changes with PHP.
If you had similar situations or have a clue on what could be causing this behavior, please comment :)
I found the solution. So if anyone stumbles upon the same problem: echo the whole head thing, everything. echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html lang="'.$language.'" xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="content-language" content="'.$language.'"> </head>';
When you echo the whole upper html tags, there are no more "hiccups" like before. Still interested to find out why they were happening in the previous code.. But this solution works well.
First, I'm in agreement with you ... that really doesn't make sense. All that processing and output happens server-side and should not make any difference whatsoever, as you have stated. I notice you are not sending out the XML declaration, but that probably isn't it either. Are you actually sending out utf-8 Content-Type headers too? Use LiveHttpHeaders extension in Firefox to see. Lastly, that html element should probably also contain the xml-lang attribute. I always put it in, anyway. Along with the text direction ... but that's me.