fresh icon indicating copy to clipboard operation
fresh copied to clipboard

Optimized bundles

Open lucacasonato opened this issue 3 years ago • 4 comments

Because bundles are generated with esbuild JIT, we can optimize bundles for each browser we are serving content to. For example the bundle shipped to Firefox 88 would need transpilation for private class methods, whereas a bundle shipped to the latest Chrome would not.

Browser version can be determined by User-Agent string. The remaining question is just if this is even a good idea.

lucacasonato avatar Jun 22 '21 12:06 lucacasonato

I don't think user agent string parsing is a good idea, because it can be spoofed, which may render the bundle broken for that browser. If possible, detecting the specific features in the browser should be used, but it cannot be done server side, of course. Server would need to send a script that checks for the required features, then, based on the browser response, generate a correct bundle.

DVSoftware avatar Jun 15 '22 11:06 DVSoftware

Also the user agent string is being deprecated anyways so already getting more and more useless.

Though client hints might be a useful alternative.

CanRau avatar Jun 15 '22 14:06 CanRau

I don't think user agent string parsing is a good idea, because it can be spoofed, which may render the bundle broken for that browser.

So what? Users don't normally spoof their user agent strings... we can always fall back to serving an "ancient" bundle for browsers which we don't recognize.

Server would need to send a script that checks for the required features, then, based on the browser response, generate a correct bundle.

At minimum this doubles TTI, so it is an unacceptable solution.

Though client hints might be a useful alternative.

When they are more widely supported across engines, yup!

lucacasonato avatar Jun 26 '22 23:06 lucacasonato

Although client hints still have a long way to go until they are supported in all major browsers, the author of ua-parser-js didn't have anything to say about supporting client hints.

But there's a bright side, it looks like people are willing to help with this.

notangelmario avatar Jul 05 '22 21:07 notangelmario

This one is a really good idea. It would help a lot mobile users not parsing old JS

tlgimenes avatar Jan 30 '23 16:01 tlgimenes