Search code examples
azureazure-static-web-appazure-static-web-app-routing

Azure Static Web App: Add an header for each JS file


I'm using Azure Static Web App to build and deploy my app.
I want to add in the Content-Type header with the following content: application/javascript; charset=UTF-8, to each JS file I serve (since all files in the dist folder are in JS, this souldn't be an issue).

I have this error: Encountered an issue while validating staticwebapp.config.json: Could not read and deserialize the provided routes file.

Here's my staticwebapp.config.json:

{
    "routes": [
        {
            "route": "/dist*",
            "headers": [
                {
                    "Content-Type": "application/javascript; charset=UTF-8"
                }
            ]
        }
    ]
}

Can you please help me?
Thanks in advance for your answer.


Solution

  • This solution is more a workaround, but just adding <meta charset="UTF-8"> in the head of my HTML file has fixed my issue.

    With this solution, the browser doesn't need to have the right Content-Type header to read the JavaScript file with the good formatting.