0

When running a Vite server in vanilla js for development or build, charset encoding changes at index.html. For specific reasons, I need the encoding to be iso-8859-15 (I know utf-8 is a more standard one, but I must use iso-8859-15) for write simple html, css and js pages (I use Vite bec workflow in the future). I declared charset encoding in index.html as follow:

<!DOCTYPE html>
<html lang="es">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-15" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
  </head>
  <body>
    <h1>ÁÉÍÓÚ áéíóú ñ ¿?</h1>
    <script type="module" src="/js/main.js"></script>
  </body>
</html>

Here is the result when running in dev mode (same on build: encoding changes): html charset render wrong on Vite dev server

This is the result of changing the encoding also in Vs Code to iso-8859-15. Browsers return that the encoding is right (iso-8859-15), but it renders as the above image.

I'm kind of new using bundlers like Vite and it's my first time asking at Stack overflow because I couldn't find answers related to fix this problem. I suppose there is a way to change encoding at the vite.config.js or that the problem is related on how node.js runs a local server, but I can't figure it out a solution.

Any ideas of why this happens and how to solve it if it's possible? Thank you very much!

omiref
  • 1
  • 1
  • 1
    UTF-8 is not "more standard": it is the only allowed encoding for modern web (since HTML5). In any case: do not link images. If the image is important: just include in the question (not as a link). But probably you can just copy the text and include text in the question. Do not expect programmers will open random links from random people. – Giacomo Catenazzi Dec 12 '22 at 07:50

0 Answers0