Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Defining CharSet for static HTML files

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

like image 351
Sami Lehtinen Avatar asked Feb 18 '23 00:02

Sami Lehtinen


1 Answers

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.

like image 91
Sami Lehtinen Avatar answered Mar 07 '23 15:03

Sami Lehtinen