News for hackers. Stuff that matters.
Re:Removing HTTP/2 Server Push from Chrome by unlog on Friday August 19, 2022 @01:03PM (#32523546)
What we need is somehow the ability to serve the html/js and json at the same time without having to wait for the client to get the html and then do the fetch request for that json. This will save a full round trip for loading content while keeping things simple.
Re:Removing HTTP/2 Server Push from Chrome by cyral on Friday August 19, 2022 @01:50PM (#32524075)
If you mean avoiding the dreaded loading spinner when loading a single page app, you can add the JSON data in some script within the HTML. This is what server-side rendering frameworks like Next.JS do. In it's simplest form, just include something like:

<script> window.initialData = { isLoggedIn: true, email: '[email protected]', todos: [ ... ] } </script>

Re:Removing HTTP/2 Server Push from Chrome by jefftk on Friday August 19, 2022 @01:11PM (#32523621)
Re:Removing HTTP/2 Server Push from Chrome by dmw_ng on Friday August 19, 2022 @01:41PM (#32523985)
Put the HTML/CSS inside the JS, make that whole bundle cacheable, and make your "HTML" response basically be one <script> tag starting the JS and another containing the JSON response.

Folk have been using this technique for a decade or more

Re:Removing HTTP/2 Server Push from Chrome by riskable on Friday August 19, 2022 @02:02PM (#32524227)
An alternative is to have a minimal HTML that has basically nothing except a <script> tag that connects to a WebSocket then have all content delivered over that. I've done testing with this in the past and it definitely outperforms HTTP/1.1 but maybe not HTTP/2 or HTTP/3 (never tested against those--this was several years ago).

I even wrote a web server with bundled framework (as an academic exercise) whose whole purpose was to work like this. It was basically made for delivering any given bundles of assets over a WebSocket and had some cool features like the ability to auto-encode, auto-compress, or translate from one file type to another (say, turning a PNG into a JPEG or minifiying JS/CSS) as a simple matter of modifying the configuration.

Re:Removing HTTP/2 Server Push from Chrome by toast0 on Friday August 19, 2022 @01:21PM (#32523749)
If you're going to serve all the js all the time, put it inline.
Re:Removing HTTP/2 Server Push from Chrome by pca006132 on Friday August 19, 2022 @01:31PM (#32523854)
It is not faster in case the js can be cached or serviced through a faster CDN comparing to your own server.
Re:Removing HTTP/2 Server Push from Chrome by kastagg on Friday August 19, 2022 @04:08PM (#32525434)
Is it slower?
Re:Removing HTTP/2 Server Push from Chrome by pca006132 on Friday August 19, 2022 @09:55PM (#32528298)
Yes, if your website that serves the webpage is slower than those CDNs, and your website cannot be cached while those js files can be cached.
Re:Removing HTTP/2 Server Push from Chrome by johnny_canuck on Friday August 19, 2022 @03:39PM (#32525205)
This sort of sounds like what 103 Early Hints aims to resolve

https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/103

Re:Removing HTTP/2 Server Push from Chrome by yread on Friday August 19, 2022 @01:29PM (#32523837)
I just generate the json when loading the page and embed it as script with a nonce. Of couse I lose the caching of the "static" page but it's worth it.
Re:Removing HTTP/2 Server Push from Chrome by GordonS on Friday August 19, 2022 @01:29PM (#32523839)
Hmm, that's an interesting idea - perhaps the browser first downloads some kind of "manifest" file, which lists the required URIs, then the browser can request them all at once?