errorception / snapshotify

Creates a static HTML snapshot for your `create-react-app` app, to improve initial page load times.
102 stars 5 forks source link

Prerender detection #12

Open redxtech opened 3 years ago

redxtech commented 3 years ago

Hello! Is there any way for the app to tell whether it's being prerendered? I know that in react-snap you can check with navigator.userAgent === 'ReactSnap', so I'm wondering if there's an equivalent for this prerenderer. Thanks \:)

rakeshpai commented 3 years ago

I must admit I haven't used this project in a while myself, but I believe this is possible. You should have a global window.SNAPSHOT = true injected into the page when running. https://github.com/errorception/snapshotify/blob/3a6bc0d50ea1d48ed110f792cb0104d00299133b/src/process-path.js#L36

rakeshpai commented 3 years ago

Yeah, this is documented in the README too:

Detecting snapshot

Sometimes, it may be necessary to detect if you are running in the snapshot mode, so that you can serve up alternative content. To enable this, a global window.SNAPSHOT variable is set to true when taking the snapshot.