为静态HTML文件定义CharSet [英] Defining CharSet for static HTML files
问题描述
文件在标题部分包含正确的meta-equiv标记。
我试过多次为Google App Engine提供的静态文件定义字符集,
< meta http-equiv =Content-Typecontent =text / html; charset = utf- 8/>
但是它并没有作为标题传递,浏览器需要从实际的文档中提取它。
当然,如果我使用脚本(或Python Google App Engine程序),那么我可以正确地将它作为响应标题发送。
Content-Type:text / html; charset = UTF-8
我尝试添加到app.yaml文件行:
- url:/
static_files:root / create.html
上传:root / create.html
http_headers :
Content-Type:text / html; charset = UTF-8
但appcfg.py只是告诉我:
意外属性'http_headers '用于URLMap类型的对象。 9oxnet / app.yaml第41行第5列
解决方案静态文件,你需要在app.yaml文件中定义字符集:
- url:/
static_files: root / create.html
上传:root / create.html
mime_type:text / html; charset = UTF-8
现在,静态文件的Content-Type标题也正确包含字符集信息。 / p>
Content-Type:text / html; charset = UTF-8
某些浏览器不会尽快解析页面,如果charset信息不是包含在标题中。
I just tried several times to define character set for static files served from Google App Engine and failed miserably.
File does contain correct meta-equiv tag in header section of file:
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
But it's not being passed as header, browser needs to pick it up from the actual document.
Naturally if I use script (or Python Google App Engine program) then I can get it delivered correctly as response header.
Content-Type: text/html; charset=UTF-8
I tried to add to app.yaml file rows:
- url: /
static_files: root/create.html
upload: root/create.html
http_headers:
Content-Type: text/html; charset=UTF-8
But appcfg.py just tells me: Unexpected attribute 'http_headers' for object of type URLMap. in "9oxnet/app.yaml", line 41, column 5
To fix this charset header issue for static files, you'll need to define charset in app.yaml file:
- url: /
static_files: root/create.html
upload: root/create.html
mime_type: text/html; charset=UTF-8
Now Content-Type header for static files also correctly contains character set information.
Content-Type: text/html; charset=UTF-8
Some browser do not parse pages as quickly as possible, if charset information is not included in headers.
这篇关于为静态HTML文件定义CharSet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!