BuilderIO / partytown

Relocate resource intensive third-party scripts off of the main thread and into a web worker. 🎉
https://partytown.builder.io
MIT License
12.85k stars 426 forks source link

[🐞] partytown-sw.js The script does not have a MIME type #469

Open AkshayKumarDhage opened 9 months ago

AkshayKumarDhage commented 9 months ago

Describe the bug

I am trying to integrate Partytown in my website and following the HTML integration. And have included partytown.js as inline script in . And have configured window.partytown with correct path for "lib".

Since partytown.js requests the partytown-sw.js, In chrome browser network tab I get 200 status for partytown-sw.js,

But in console it throws error: DOMException: Failed to register a ServiceWorker for scope ("https://www.example.com/static/js/src/partytown/lib/") with script ("https://www.example.com/static/js/src/partytown-sw.js"): The script does not have a MIME type

I checked if there is any issue in the path of file but that's not the case, as going to link https://www.example.com/static/js/src/partytown-sw.js gives the correct JS file in browser.

I definitely think this issue is related to Partytown service worker file, as I came accross a blog where some author mentioned above same MIME type issue with the loading of Partytown Service Worker file. Blog link: https://maxchadwick.xyz/blog/experimenting-with-partytown

(I tried with latest version of Partytown, it still has this error)

Any quick help or fix or workaround on this is highly appreciated!!

Reproduction

https://maxchadwick.xyz/blog/experimenting-with-partytown

Steps to reproduce

  1. Do HTML integration for Partytown
  2. Include partytown.js as inline script in
  3. Now go to Chrome/Firefox browser and load the website
  4. Check the console, it will throw error that partytown-sw.js file doesn't have a MIME type.

(I only tried the latest Partytown version, not sure about old versions)

Browser Info

Chrome, Firefox

Additional Information

No response

mhevery commented 9 months ago

The mime type is controlled by your server... I think you need to configure it?