iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
😱

Delivering Web Pages in Shift_JIS or EUC-JP via GitHub Pages Causes (Likely) Unavoidable Encoding Issues

に公開

The Problem I Faced

When hosting web pages encoded in Shift_JIS or similar encodings on GitHub Pages, I encountered garbled text when viewed in a browser, which was problematic.

<meta charset="Shift_JIS">

This happened despite specifying the charset.

Why?

This is because GitHub Pages always specifies charset=utf-8 in the Content-Type response header.

Github Pages server always specifies utf-8 in header regardless of meta tag · community · Discussion #22867
html - Github Pages change content char set - utf8 and windows1256 Arabic - Stack Overflow

At least in my environment (Chrome), even when specifying the character code with <meta charset=>, the Content-Type header's specification seemed to take precedence.

In conclusion, if you use a character encoding other than UTF-8 with GitHub Pages, it seems difficult to prevent garbled text when viewed by general users in a browser. If it is essential to use character codes such as Shift_JIS or euc-jp for some reason, you should be careful when selecting a hosting platform.

How I Noticed This

I was working on fixing a problem where openGraphScraper would retrieve garbled OG information from non-UTF-8 websites.

Add character encoding detection and decoding logic by cm-dyoshikawa · Pull Request #206 · jshemas/openGraphScraper

I noticed this when I viewed HTML encoded in a non-UTF-8 charset that was uploaded to GitHub Pages as test data, and it appeared garbled in the browser. Since it didn't hinder the automated tests for decoding capabilities, I decided to overlook it. I explained this to the maintainer, and the PR was successfully merged.

Discussion