PhileCMS / Phile

A flat file CMS with a swappable parser and template engine.
https://philecms.github.io/
Other
257 stars 49 forks source link

HTTP response header should specify charset #166

Closed gexclaude closed 9 years ago

gexclaude commented 10 years ago

It would be good if Phile would specify the charset in the HTTP response headers:

header('Content-Type: text/html; charset=utf-8');`

This cheers browser up as they don't need to determine the charset based on the content or the meta-tag.

Frodox commented 9 years ago

@gexclaude, And what if content's charset is not utf-8 ? Maybe we should take it somewhere (add there) from settings (config.php)?

@NeoBlack, does ready label mean that someone already implement it? or is it open for PRs ?

gexclaude commented 9 years ago

@Frodox config entry would also be good.

james2doyle commented 9 years ago

I don't know much about text encodings, but when is HTML not UTF8? I know the markdown content can be whatever, but in this case it's the HTML output we are talking about here.

gexclaude commented 9 years ago

Well the default theme sets the charset to utf-8, but as I saw Phile didn't set any HTTP header. Thus charset from the HTML can differ from the encoding used to send the response. This is because PHP will use the default charset configured in php.ini AFAIK if no HTTP Header is sent before the response is built. But with that I'm also not a 100% sure.

Other question - in what case would you want NOT to use UTF-8?

james2doyle commented 9 years ago

I'm not sure. I think someone that provides non-latin-based languages might have to weigh in. I don't think languages like Chinese or Arabic use UTF-8 right?

gexclaude commented 9 years ago

Well they can. Actually UTF-8 supports it very well. IMHO there is no encoding that is more widely supported.

See http://www.quora.com/What-is-the-best-encoding-for-Chinese-simplified-characters for instance.

But what about making this a config parameter and set the default value to UTF-8 and thus have the, IMHO, best default in place?

Schlaefer commented 9 years ago

:+1:

I have no strong opinion about it but it's probably a good idea. Only question: should it be set in template too? People could think they could overwrite the encoding there and end up with a mixed declaration. Anyhow I would go with:

james2doyle commented 9 years ago

The config solution makes the most sense. I think it could also be defined as a constant, like the markdown extension (.md) is.

This can still be referenced in TWIG as well like this {{ constant('CONSTANT_NAME') }}

james2doyle commented 9 years ago

oops closed by accident

Schlaefer commented 9 years ago

Closed by PR #179