Invalid or unexpected token (at browser-detect...)

AI-generated summary

Invalid or Unexpected Token Issue

V102918 encountered a JavaScript error “Invalid or unexpected token” on files ending in .gz.js. Despite the presence of a Content-Encoding: br header, the issue persisted. Falco suggested a misconfigured CDN, specifically pointing out a missing gzip content encoding header.

V102918 discovered that the error occurred after migrating from DigitalOcean Spaces to Backblaze, where the Content-Encoding metadata was not transferred. Deleting the assets folder in Backblaze and attempting to re-upload assets using rake s3:upload_assets resulted in skipped files.

Falco recommended a rebuild to re-upload missing assets, which V102918 successfully implemented, resolving the issue after clearing the cache.

Hi all,

I’m receiving some JS errors saying invalid or unexpected token, all coming from files that end in .gz.js

I had a look at this thread here: Stackpath (Formerly MaxCDN) - Invalid or Unexpected Token which suggests that the content-encoding header is missing, however it is present for those files and it shows Content-Encoding: br

What can I do to fix this?

Here’s the headers returned:

Are there any other headers missing here that’s causing this?

Thanks for any help you can provide.

Looks like your CDN is misconfigured. For example, https://forumcdn.minnitchat.com/assets/browser-detect-18068a2d9ee3b1943a0bea70aa916d391f1dc6c03eeb7917ead5d6e0a637321a.gz.js should have a content encoding of gzip but the header is missing.

This error happened when I migrated from DigitalOcean Spaces to Backblaze.

It seems that the Content-Encoding metadata wasn’t transferred over when I copied over files from DigitalOcean Spaces to Backblaze.

So I decided to delete the assets folder in Backblaze.

Is there a way to force all of the assets to be reuploaded?

When I run rake s3:upload_assets, I see the following:

rake s3:upload_assets --verbose
Installing CORS rules...
skipping
Skipping: assets/discourse-57df4f51068d4926f4e9170d2001380eadd7942574a11a99540a7fb39a0d5933.js
Skipping: assets/discourse-57df4f51068d4926f4e9170d2001380eadd7942574a11a99540a7fb39a0d5933.br.js
Skipping: assets/discourse-57df4f51068d4926f4e9170d2001380eadd7942574a11a99540a7fb39a0d5933.gz.js
Skipping: assets/vendor-01a1a73134b66697f73050c52550416a7a4ca1be2731823d24d3c3db03de62dc.js
Skipping: assets/vendor-01a1a73134b66697f73050c52550416a7a4ca1be2731823d24d3c3db03de62dc.br.js
Skipping: assets/vendor-01a1a73134b66697f73050c52550416a7a4ca1be2731823d24d3c3db03de62dc.gz.js
Skipping: assets/admin-e9a41caf10a7034a459f1ea903e10fdf4b4521ccfc457f9a4eec9a2f202968d9.js
Skipping: assets/admin-e9a41caf10a7034a459f1ea903e10fdf4b4521ccfc457f9a4eec9a2f202968d9.br.js
Skipping: assets/admin-e9a41caf10a7034a459f1ea903e10fdf4b4521ccfc457f9a4eec9a2f202968d9.gz.js
Skipping: assets/wizard-2a333f23a04838384081055016eee4318c873ebc8188d13fa84c86b12deabd7a.js
Skipping: assets/wizard-2a333f23a04838384081055016eee4318c873ebc8188d13fa84c86b12deabd7a.br.js
Skipping: assets/wizard-2a333f23a04838384081055016eee4318c873ebc8188d13fa84c86b12deabd7a.gz.js
Skipping: assets/test-support-9ed31303d935a668f483d777d27ba04733f5c99d518b1379b45b3959f53937ea.js
Skipping: assets/test-support-9ed31303d935a668f483d777d27ba04733f5c99d518b1379b45b3959f53937ea.br.js
Skipping: assets/test-support-9ed31303d935a668f483d777d27ba04733f5c99d518b1379b45b3959f53937ea.gz.js
Skipping: assets/test-support-9ed31303d935a668f483d777d27ba04733f5c99d518b1379b45b3959f53937ea.js.map
Skipping: assets/test-helpers-b76fd4fd8c6b418680cdb0cacdebb7946b25abec19237a0d15d174b01b3f36eb.js
Skipping: assets/test-helpers-b76fd4fd8c6b418680cdb0cacdebb7946b25abec19237a0d15d174b01b3f36eb.br.js
Skipping: assets/test-helpers-b76fd4fd8c6b418680cdb0cacdebb7946b25abec19237a0d15d174b01b3f36eb.gz.js
Skipping: assets/test-helpers-b76fd4fd8c6b418680cdb0cacdebb7946b25abec19237a0d15d174b01b3f36eb.js.map
Skipping: assets/test-site-settings-3e7fd4983053d4b7813cac2dce831768a7bc09d15e2d563b026a4a805ca4477e.js
Skipping: assets/test-site-settings-3e7fd4983053d4b7813cac2dce831768a7bc09d15e2d563b026a4a805ca4477e.br.js
Skipping: assets/test-site-settings-3e7fd4983053d4b7813cac2dce831768a7bc09d15e2d563b026a4a805ca4477e.gz.js
....

How do I force it to reupload those assets into Backblaze?

A rebuild should re-upload all missing assets

Thanks – I ran a rebuild and it seems to be working properly now (after clearing cache)

Appreciate your help