If you have the <html> and <head> tags split between an include php file and you have the rest of the <html> and <head> at the top of an html file, can it cause a “specify a character set” error? Are there other problems with doing this? I’m trying to use an include for all that beginning stuff and start the html file with the include reference and then the <title>. Titles are (should be) unique to each html file, but the other code is not - so why not use an include for the non unique code.
Raplph,
Thanks for writing. Maybe I should back up. I’m geting a specify a character set error from Pagespeed, yet I have the same DTD code and other inital code in anothe site and no problems. The only difference is the code for one is in wordpress and no error and the code for the other is split up. What should I do to figure out the problem? No errors via Total Validator, nor W3C validation.
Scallio,
I put in the header
<meta header(‘Content-Type: text/html; charset=utf-8’) /> and took the same info out of the include. The error I’m getting is
I tried it without the ’ and ’ and no difference. In case “header” referred to the name of the include file, I changed “header” to the name of the include file and still have the same error - lacks value, specify a charset.
Scallio, Lesley,
<?php
header(‘Content-Type: text/html; charset=utf-8’) ?>
<!-- rest of file goes here –>
Worked (no charset error in PageSpeed), but strangely page source code doesn’t show charset code.
This
<META http-equiv=“Content-Type” content=“text/html; charset=UTF-8”>
I hoped would work and tried it prior but I forgot the equiv code. I wold think with the equiv code it would work but it just doesn’t. The quirk in Apache (I guess) made Scallio’s placement comment necessary (<!-- rest of file goes here –>); when I tried putting in the index.html file the include reference first and the <?php header('Content-Type … second, still had the page speed charset error.
Me either. So is the issue resolved? The header that Remon (ScallioXTX) provided should do the trick, but normally the meta tag is included also as a fallback, just after the opening <head> tag.
Ralph,
I put it in and it doesn’t cause any problems, but it seems kinda strange.
The code
<?php header(‘Content-Type: text/html; charset=utf-8’) ?>
is put in in case
<META http-equiv=“Content-Type” content=“text/html; charset=UTF-8”>
doesn’t work
and
<META http-equiv=“Content-Type” content=“text/html; charset=UTF-8”>
is put in in case
<?php header(‘Content-Type: text/html; charset=utf-8’) ?>
doesn’t work.
Basically your server is meant to handle the content type, but because it doesn’t seem to be, Remon suggested the PHP fix. It’s normal to put the meta tag in too, and I’ve heard different reasons why, but I guess it helps in situations such as when you are viewing the pages offline and so no server is sending header information. I’d be happy for someone to give a better explanation, though.
Ralph,
I wondered about SEO vs loading speed on that. I had the style sheet reference up high to get the page to load faster but doing that does push the title down one chunk of code. Is that what you were thinking-title is the most important, get it as high as possible?
The position of the CSS file doesn’t haven’t an impact on loading speed, since it will have to be loaded anyway so it doesn’t matter when it will be loaded. The position will maybe change the loading time of the page a few picoseconds, but it’s really not worth the trouble changing this.
It’s a good idea to put the Content-Type tag first so the browser knows everything in the head is encoded in that type, but other than that I’m pretty sure it doesn’t matter one bit.
As for the whole php vs meta tag for character encoding debate you guys had going earlier, Ralph was correct in everything he said
We all have our likes and dislikes. It makes sense to me to have the title after the character encoding, followed by any other meta stuff, and then add in styles, then any script links etc. It’s more likely that new style sheets or script links will be added in later, so I like to have them grouped together (although I usually put script links just before the closing </body> tag these days.
Sometimes when people post here you look at the head section of their site and there is a huge mixture of things there … a meta tag, a css file, a few scripts, andother css file link, some more meta data … It just looks like a really big mess to me, and I like to keep things tidy.