"Unexpected token '<'" after SvelteKit redeploy

Viewed 109

After new CI build and redeploy of my app written with SvelteKit (static adapter) I often get the error Unexpected token '<' in the browser when I access it.

Hit browser refresh solve the issue. Therefore I am guessing there is a cache issue but absolutely not sure about it.

Did anyone ever faced the issue and managed to resolve it?

1 Answers

A new deploy generates new filenames for the javascript files that have changed, when the (cached) html tries to load javascript based on an old filename the server responds with an 404.

The 404 page probably starts with <!DOCTYPE html>
(the first "<" character is the unexpected token)

To resolve this you could try to reduce cache lifetime of the html files or don't delete the old javascript files when deploying, but only add & replace files.

Related