Defining CharSet for static HTML files

2019-05-07 09:45发布

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条回答
Juvenile、少年°
2楼-- · 2019-05-07 10:09

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.

查看更多
登录 后发表回答