DEV Community

Cover image for Differential Serving

Differential Serving

John Stewart on May 01, 2019

Recently I was listening to the Shop Talk Show and heard about differential serving. The idea behind differential serving is that you serve differe...
Collapse
 
danielschaffer profile image
Daniel Schaffer

Hi there! Just wanted to add that I've got Yet Another Webpack Plugin to help with this - github.com/DanielSchaffer/webpack-...

It's a little different in that it attempts to avoid the requirement of manually adding the link scripts to your template - it updates the HtmlWebpackPlugin data so that it happens automatically. There's also code to avoid emitting duplicate CSS files.

Collapse
 
philnash profile image
Phil Nash

I like the idea of this, but I'm never a fan of user agent sniffing and the double download/running of code seems like a bad thing. Is this really ready for the mainstream yet?

Collapse
 
jovidecroock profile image
Jovi De Croock • Edited

The thing with the double download is very specific to IE11 and that one Safari version, that one safari version can be fixed with a script (standard included in the webpack-module-nomodule-plugin) but the one from IE11 seems a whole lot different. I do think that with the deprecation of IE11 coming up soon'ish we shouldn't worry about it that much but rather provide compatability to legacy and reward people using modern browsers with a quicker loading path.

That's my two cents on the matter, ofcourse we could also search for a second compat script to prevent double download.

To be honest, I should just test it with deferring the nomodule but haven't come to that yet.

Collapse
 
philnash profile image
Phil Nash • Edited

This is a good point. It's definitely a good technique to shrink bundle size and that's likely worth it alone.

I'll have a play around with it myself.

Collapse
 
thejohnstew profile image
John Stewart

Curious to know why user agent agent detection is a problem?

It seems there is a widely used and well supported project within the node ecosystem to do this and to do it well.

npmjs.com/package/useragent

I think it is ready for mainstream. It's a matter of understanding what browsers your customers are using and trying to ship JS to specific browsers. As far a performance goes, you get some benefits of sending less code on newer browsers and the newer browsers are optimized for the new JS as well. And on the older browsers they are getting the same JS they would have got anyways.

I agree the double download could be a nonstarter but with user agent sniffing the worst case there is the current situation.

Collapse
 
philnash profile image
Phil Nash

I've never been a fan of user agent sniffing because of the unpredictability of the user agents, I prefer feature detection, which was the initial intention of the two script tags.

I like that there's a community supported project in Node, but that doesn't sort things for other language ecosystems or staticly rendered sites either. I admit, that when the worst case is the fallback to ES5 transpiled code, it's not the worst thing and the potential benefits probably outweigh my concern.