best practices for .pages.dev domain
Hey, I‘m looking for a way to handle the standard .pages.dev domains. I would like to keep headers and cache settings out of my application, cause I thinks it‘s not business logic related as much.
So I added page and transform rules for the official domain and it works great, but I‘m don‘t know how to handle the preview generated subdomains for the project. I don’t want that it‘s possible to access the page by the .pages.dev domain, so I added a bulk redirect for it. Works fine as well, but I want to keep the preview urls accessible with custom no-follow tags.
Is it possible to achieve that?
7 Replies
Generally, I would recommend
_headers
. Can you go into more detail about why you prefer managing this stuff in the dashboard with other tools?Yes of course, from my point of view, everything headers related, has generally nothing to do with the required code to build an application. Headers are little bits and pieces that make my application more secure, more performant (cache-Headers) or restrict indexing by crawlers. So if I want to change one of those headers in code, I have to alter files, make a pull request and a new deployment. Many developers don‘t know much about security related headers and so I thinks it would be a good practice to configure those infrastructure and traffic related stuff directly by defining specific rules to manage it from the dashboard.
For the official domain of my pages projects it works great! But it‘s also possible to access the project by the pages domain and it would be awesome, if the subdomain appears as a site in cloudflare to make all the great customization options for it accessible as well. Does that make sense to you?
So when talking about the
_headers
file, do know where to locate it within a sveltekit project? Can‘t find anything about it in the documentation 😦Gotcha. Yeah, that makes sense, but I think probably easiest to just try out
_headers
for now, and we'll take note of your feature request for more control over your *.pages.dev
domain in the dashboard.You can create an
_headers
in your static
directory of your SvelteKit project: https://kit.svelte.dev/docs/project-structure#project-files-staticSvelteKit docs
Project structure • SvelteKit documentation
That'll get brought across into your "Build Output Directory" when we run your build command.
Already tried that, but didn‘t work. Will give it another try thanks!
Awesome! Thanks!
But if I‘m remembering it correctly the docs say that the _headers file has no effect on dynamic content, so I‘m responsible for managing those cache headers etc within code or am I wrong?
Yes, that is correct. It only affects static asset responses.