1cg
February 15, 2022, 4:43pm
1
Hi There!
I would like to have the same URL respond with different content, depending on the Content-Type
header.
Is that possible via file based configuration ?
Or, even better, if I just drop an index.js
alongside a index.html
, will that work?
Thank you, love netlify!
coelmay
February 15, 2022, 8:44pm
2
Hey @1cg
The only way I know of serving different content based the Content-Type
request header is to use functions .
Can you offer more information about what it is you are trying to achieve?
1 Like
1cg
February 15, 2022, 10:29pm
3
Thank you!
Basically I want a url, https://demo.htmx.org , to return html content if someone navigates to it, but return javascript if someone includes it via a script tag.
I was hoping there was some way to set up the default file based on the content type using the toml file: a function for just that probably isn’t worth it.
Thank you for the suggestion though!
This is not something configurable by a user. However, you can use redirects to some extent. If you call the URL like:
https://demo.htmx.org?script=true
You can use redirects with query parameters to forward that to your JavaScript file.
i ended up making this work with two steps:
works perfectly, with the correct content-type taken from the redirect!
Thank you netlify!