kit icon indicating copy to clipboard operation
kit copied to clipboard

Prerender routes json

Open colecrouter opened this issue 3 years ago • 7 comments

Problem

Prerendered pages on adapter-cloudflare should not require a worker request. See issue for more info #7298

Solution

Prerender pages as /foo/index.html instead of /foo.html, then exclude /foo in _routes.json. This will bypass the worker entirely, and still serve the prerendered page.

I ran the test suite, and tested it on my site with vite dev and deployed to Cloudflare Pages. I got the feeling that the change to packages/kit/src/core/prerender/prerender.js would cause more friction that it seemed to.

colecrouter avatar Nov 17 '22 23:11 colecrouter

⚠️ No Changeset found

Latest commit: 0566ee2d5d8c6d7722da0c098c3ce23d906bc0b7

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

changeset-bot[bot] avatar Nov 17 '22 23:11 changeset-bot[bot]

Y'know, I suppose it would break the prerender tests, wouldn't it? haha

colecrouter avatar Nov 17 '22 23:11 colecrouter

Not sure about that last test. I can't seem to get goto() to react to anything.

colecrouter avatar Nov 18 '22 00:11 colecrouter

Thanks you but we can't just change about.html to about/index.html willy-nilly. One means /about, the other means /about/.

I'm also not sure this approach scales very far. There's quote a low limit to the number of entries you can have in your _routes.json (100 for include and exclude combined, IIUC) which many sites would immediately exceed.

Rich-Harris avatar Nov 18 '22 19:11 Rich-Harris

Thanks you but we can't just change about.html to about/index.html willy-nilly. One means /about, the other means /about/.

That's what I've been alluding to in #7298 . I've got it working to Cloudflare's spec using wrangler, and vite dev the behavior seems to function identically, but I don't know what the exact expected behavior to start with (if different). /about still resolves correctly, and /about/index.html still 404s (when I was testing). Although I can't speak to /about vs /about/, Chrome usually changes that automatically 😅

The one failed test says something is wrong, but I can't seem to get it to work no matter what I do (I'm not too familiar with playwright, unfortunately). Aside from that, it seems to work fine for me "in practice".

I'm also not sure this approach scales very far. There's quote a low limit to the number of entries you can have in your _routes.json

~100 prerendered pages? How about adding a cap, or a switch + warning if over 100 entries. Then the worst case would be what's currently happening.

colecrouter avatar Nov 19 '22 01:11 colecrouter

@Mexican-Man is attempting to deploy a commit to the Svelte Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Dec 07 '22 00:12 vercel[bot]

Instead of automatically excluding prerendered pages, I've put in an adapter option that lets you manually specify if you want to bypass. That seems a lot safer. The Vite exports for prerendered pages are working properly now, so any prerendered test errors seem to be resolved (on my computer).

colecrouter avatar Dec 07 '22 00:12 colecrouter

I merged #8422, which adds all assets and prerendered pages (up to the 100-rule limit), so I'll close this — thanks.

In general I think the automated approach is preferable to manually specifying exclusions, though in the rare cases that it is necessary it could be done by modifying the _routes.json after it's been created.

Rich-Harris avatar Jan 20 '23 00:01 Rich-Harris

Bit late, but just wanted to say thanks. I just took a look at last month's bill, and we're down 85% on billed requests 😊(just from prerendered pages, alone). HUGE; thanks @Rich-Harris!

colecrouter avatar Feb 08 '23 06:02 colecrouter