MIME type issues with functions?
Refused to execute script from 'https://example.com/myfunction.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
CODE:
I am not exactly sure what I am doing wrong..
8 Replies
Are you using Pages Functions?
or is this a normal js file you want to execute?
If the former, you don't call it in your HTML, it's just invoked when you go to the path
Pages function, since the goal is for it to interact with D1
I understand what you mean now, but this means that I need to have a function to get my HTML and return a modified version of that HTML as a response then, right?
Sure if you want to rewrite the HTML, you can checkout HTMLRewriter - https://developers.cloudflare.com/workers/runtime-apis/html-rewriter/
You can also use it as an API and return like a JSON which you handle client-side.
oh cool, thanks
this appears to be exactly what i need
but
if it is rewriting, then how does it get the initial html?
fetch(req) will fetch from behind the Worker (so an origin)
ah ok
HTMLRewriter docs show that too 🙂
ah, i see it now,
transform()
is what i was looking for