sveltejs / sveltejs/kit

Does not work with Google Signed Exchanges

Open
#11,949 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

Describe the bug

Google Signed Exchanges (SXG) allow Google search to prefetch your content while preserving the users privacy, and also enhancing your websites performance. It can lower LCP significantly for example.

The way I came across this issue is that Cloudflare has a feature that is off by default that will enable SXG. This means your site is served from https://<site_name>.webpkgcache.com/doc/-/s/<site_name>/

For example, if a user clicks on a SvelteKit app from Google Search results that is served from an SXG, the initiator chain would look like the following for a js file:

https://<site_name>.webpkgcache.com/doc/-/s/<site_name>/<path>
  --> https://<site_name>/<path>
            --> https://<site_name>/_app/immutable/entry/app.<hash>.js
                      --> https://<site_name>/_app/immutable/nodes/13.<hash>.js

As you can see the originator is the SXG. This breaks the app, as it will get a 404 not found for the .js file, because the app.<hash>.js and entry.<hash>.js is referencing a path that no longer exists because its expecting origin to contain these files since these files were referenced originally. I do not know why the SXG is caching app, and entry locally and not the others but if you read the docs on Signed Exchanges it says that they will pre-fetch certain files such as HTML, Javscript, CSS, etc. in a privacy-preserving manner.

https://developers.google.com/search/docs/appearance/signed-exchange

Reproduction

This is not too difficult but can be a bit time consuming. You will need to create SvelteKit app with several pages. These pages need to load several components into them, as well as CSS, etc.

Then upload this to Cloudflare Pages or some other hosting provider as long as you use Cloudflare Proxying. Enable Cloudflare Signed Exchanges. Submit your site to Google Search console and let it pickup your site. Then on Google Search Results click on items and observe the initiator chain. It does NOT serve ALL your search results from SXG, only a subset and the link on hover of the search result can be misleading as it sometimes lists the exchange url and sometimes not. The best way to see is to look at the Requestor initiator chain in Google Chrome DevTools for the item, in the network tab, under initiator for that specific item.

Logs

No response

System Info
Only Chrome and Chrome on Android
Severity

serious, but I can work around it

Additional Information

I am not sure how this can be fixed, but this does work perfectly fine using NextJs as I have several sites running with SXG enabled with no issues.

Also related to #9089

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with a SvelteKit app served through Cloudflare Signed Exchanges, then inspect the JavaScript requests and initiator chain in Chrome DevTools. Compare the SXG-served paths for app..js and entry..js with the origin paths; done means the required JavaScript assets load without 404 responses from an SXG result.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.