-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adapter-cloudflare: serve prerendered pages and static assets using _routes.json
#7298
Comments
I've made a proof of concept. It uses a Note that |
This is a blocking issue for me as well. I do not think that the |
That's good to know, I'll keep that in mind.
I think this would require a very large breaking overhaul to how SvelteKit compiles. However, the |
I think static assets were addressed in #6530. Maybe prerendered pages weren't though? |
Here, it looks like static assets are not (unless favicon). Check out the comment there, I'm not really sure what I would do in that case. On the other hand, prerendered pages wouldn't work anyway, because they're not being outputted to the right folder/name. In my fork, I worked around the assets (literally just comment the line), but working around the prerendered pages is janky. In short, we could add static assets, but that would disregard the comment made by the Pages crew. We could add prerendered pages, but in a way that's janky/messes with stuff. |
I've redone my branch and modified how static pages are outputted. Interestingly, it seems like they were intentionally set up this way(?). See my commits here. Couldn't say why, no one seems to be chiming in. My fork seems to be working and passes all the tests, so I'm just going to use that for now. If no one has anything else to add, I'll submit a PR. As for static assets, at least those are cached by Cloudflare ¯\_(ツ)_/¯ |
maybe related to #7640 which @jrf0110 and @Rich-Harris had begun to look at a bit? |
Regardless of what is implemented, I think it would be extremely invaluable to be able to override - weather it's manually adding paths or removing paths that would be automatically added. |
To be clear, this is an authoring convenience only. Under the hood, your
See this conversation: #6530 (comment). The tl;dr is that someone might add their own |
Yes, that's what I was talking about in my earlier comments. Is there a way or us to track that "upstream auth" middleware, or do we just say "excluding prerendered routes is good enough for now".
The (my) main concern is/was spending requests on just HTML assets (which are not cached by default on Cloudflare, along with worker responses). That being the case, calls to HTML files make up 80% of my current requests (again, until I bypass caching behaviour). In my own eyes, my revamped solution is "good enough". Realistically, you'd have to bypass this behaviour anyway if your site has a lot of endpoint calls, but that's still a fairly big drop in worker calls (again, 80% for me, and I don't even have to add any hooks or anything for *I can PR it later, I just want to make sure I'm not missing something obvious |
It didn´t. I was wrong. You were right. Sorry. |
what is the reason for creating a single _worker.js instead of a function for each endpoint? won't that mean cloudflare will serve the static assets on its own? or will github count a request to a file which didn't invoke a function (static) towards the usage anyways? |
Cloudflare charges per "function" aka per Worker invocation. Requests to static assets on the site are not billable.
Consistent behaviour across platforms. Cloudflare Pages might serve assets, match paths, match URLs, etc. differently from the way SvelteKit wants to. That being said, it's easier just to let SvelteKit handle all of it, even if it causes extra Worker invocations (billable). For example, Cloudflare Pages lets you have a static
They get served the same way, and still get cached (luckily). The difference, as Rich mentioned above, is that every call to a static asset now invokes a Worker (unnecessarily, 99% of the time). |
I believe this was just implemented in #8422 |
Describe the problem
From what I've seen and tested (please correct me), sites deployed via Cloudflare Pages still process prerendered pages (
export const prerender = true;
) and static assets through_worker.js
. This means that even requests to static resources contribute to the host's "function calls" budget.Describe the proposed solution
This recently updated Cloudflare doc indicates that
_routes.json
can be used to bypass_worker.js
, which typically handles all requests. By restructuring the build output folder (to serve static assets as they are normally routed in-app), we could take advantage of this feature. This would make adapter-cloudflare infinitely more viable for high traffic sites.Alternatives considered
Importance
i cannot use SvelteKit without it
Additional Information
I understand that traditionally, the contents of the build output folder is not meant to be exposed, and that
_worker.js
is meant to handle every request, even for static assets. However, I think that falling back onto Cloudflare Page's built-in file routing would be well worth it if it meant saving actual money on hosting costs (or in my case, having my site stay live for the whole day).The text was updated successfully, but these errors were encountered: