partytown
partytown copied to clipboard
Add new parameter to resolveUrl (cors: boolean)
The reverse proxy feature is excellent to combat CORS. We've found some friction with it if we want to configure it with Google Tag Manager or other tag managers.
- We can route all traffic through a reverse proxy to mitigate CORS, but this can increase bandwidth usage and increase pricing depending on caching rules.
- We can configure all domains we should run through the proxy but that makes us a bottleneck when marketing folks want to add their scripts.
My suggestion here is to change the signature of resolveUrl. Current:
resolveUrl(url: URL, location: Location): URL | undefined | null
New:
resolveUrl(url: URL, location: Location, cors: boolean): URL | undefined | null
Hear me out :) First-time resolveUrl is called with cors false. If the request fails because of cors we try to fetch again and set cors to true. Now, we can only route the scripts missing cors headers through our reverse proxy.
I'm curious what you think, I don't mind implementing this feature with the proper guidance :)
oh that's interesting, or we can allow a lower level replacement of the fetch implementation entirely so you could patch in special logic like this yourself. will leave this issue open for discussion