4 ms·
If your definition of "static site" is simply that the server doesn't generate any HTML at request-time, then any SPA is "static" (just one empty index.html and
by arkanciscan 7y ago
If your definition of "static site" is simply that the server doesn't generate any HTML at request-time, then any SPA is "static" (just one empty index.html and a web packed bundle.js generated at compile-time and an API call does the rest). But if that's the case the static future started about 7-8 years ago!
Personally I think that if your client script is making AJAX requests that patch the content of the document after the initial HTML is loaded and there's no other way to see that content then it's not a static site. In other words, a static site to me is simply one that works with JavaScript turned off.
The author seems to be talking about JamStack, where-in every change to the content of the site constitutes a recompile. I have serious reservations about using that technique on a site with many users making changes, like a social network or a comment section.
Also, since you're all probably gonna try to fight me; there's nothing wrong with SPAs, and Gatsby and Next.js both do SSR which ticks my "works without JS" box.
- MereInterest 7y agoYeah, that's definitely a non-standard use of "static". If I can't just point my browser to a local index.html sitting in a folder somewhere, it isn't a static webpage.
- MaxBarraclough 7y agoBut that's the point, an SPA could well meet your definition. An SPA could take the form a single index.html file and make use of APIs + JavaScript, rather than pages generated dynamically by the server.
- zozbot234 7y agoI'm pretty sure that API responses are generated dynamically by the server. Is there really that big of a performance impact server-side between "rendering" full HTML vs. generating JSON?
- MaxBarraclough 7y agoIf the JavaScript is small and efficient, I would guess the overhead is little more than the extra roundtrip that you'd avoid if you just delivered the HTML pre-baked. A slight aside: Dynamically producing HTML (avoiding client-side JavaScript) is now back in vogue with a rather silly buzzword: server-side rendering. Presumably coined by someone who doesn't understand what 'render' means. https://alligator.io/react/server-side-rendering/ https://alligator.io/react/server-side-rendering/
- MereInterest 7y agoHmm, good point. I think I would add that for it to be a static site, it must also be fully functional when there is no network access. A SPA that, for example, generates the Mandelbrot set and displays it, would fit this definition. A SPA that asks google for stock prices and displays them would not be, because there is additional data being requested outside of the static files served.
- MaxBarraclough 7y agoInteresting point. Wikipedia's definition of 'static web page' quite explicitly includes pages that use JavaScript, it just precludes the server from dynamically generating the pages. To quote: Dynamic functionality must be performed on the client side. An SPA would be expected to use APIs, which wouldn't be static, but if we treat the APIs as separate from the static web page, they might still make the cut. This random article [1] considers API-powered static website not to be a contradiction. [0] https://en.wikipedia.org/wiki/Static_web_page https://en.wikipedia.org/wiki/Static_web_page [1] https://hackernoon.com/quickstart-an-api-powered-static-website-1cc140205df9 https://hackernoon.com/quickstart-an-api-powered-static-webs...
- arkanciscan 7y agoI didn't mean that a static site doesn't use JS at all, just that it can still work when JS is disabled. It's not that we necessarily expect people to turn off JS, but that the site can still be fully represented using only static files.