ezekielchentnik / preact-pwa

Super fast progressive web app with small footprint & minimal dependancies
https://preact-pwa-yfxiijbzit.now.sh/
MIT License
511 stars 45 forks source link

Usage without Express? #6

Open kurtextrem opened 7 years ago

kurtextrem commented 7 years ago

Is it somehow possible to make a static build, using preact to string and then upload it to a server that doesn't run node?

ezekielchentnik commented 7 years ago

I like this idea and had thought of the same thing; in fact, if done right i think it could actually make this thing even faster (obviously depending on what you need for prerender in the app shell/index.html)

My plan was to create an npm script called 'prerender' or 'static' that would effectively run the root.js route and generate a static index.html file in /build.

I'd love to hear your thoughts & expectations to help me build this out.

cheers!

kurtextrem commented 7 years ago

Sounds exactly what I had in mind 👍 Actually I've asked the author of Preact, but he didn't answer: https://twitter.com/kurtextrem/status/833217690059825152 - maybe you could push?

developit commented 7 years ago

Ah - sorry for.missing those tweets, I don't scan for #react tweets, only #preact ones. I think a lot of people use static-site-generator-webpack-plugin.

I actually set this up for preactjs.com but ended up switching back to just prerendering the App Shell instead of the whole app. If you want to see what the full page-by-page prerendering looked like though, it's on an ssr branch:

https://github.com/developit/preact-www/tree/ssr?files=1

kurtextrem commented 7 years ago

Thank you Jason, that's exactly what I'm looking for. Great to hear that we're not the only one looking for such things :)

What made you switch back? Were there any drawbacks?

developit commented 7 years ago

The frontend dynamically fetches markdown files from a content/ directory, and shows a loading spinner while doing so. When I pre-rendered everything with seeded data, it would just immediately rip out the prerendered markdown and replace it with a spinner. I might revisit though, it's possible appending the source markdown as data to the page (via a <script> tag) would work.