Defining CharSet for static HTML files

狂风中的少年 提交于 2019-12-07 07:04:56

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/14091236/defining-charset-for-static-html-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!