开发者

Why doesn't Facebook combine its CSS/JS files?

开发者 https://www.devze.com 2023-04-07 22:54 出处:网络
I am curious as to why the Facebook developers have chosen to not combine their scripts and stylesheets into single files. Instead they are loaded on demand via their CDN.

I am curious as to why the Facebook developers have chosen to not combine their scripts and stylesheets into single files. Instead they are loaded on demand via their CDN.

Facebook is obviously a very complex application and I can understand how such modula开发者_开发问答rity might make Facebook easier to maintain, but wouldn't the usual optimisation advice still apply (especially given its high level of usage)?

Or, does the fact that they are using a CDN avoid the usual performance impact of having lots of small scripts / styles?


In a word BigPipe. They divide the page up into 'pagelets' each is processed separately on their servers and sent to the browser in parallel. Essentially almost everything (CSS, JS, images, content) is lazy loaded, thus it comes down in a bunch of small files.


They might be running into the case where the savings of being able to serve different combinations of JS files to the browser at different times (for different pages or different application configurations for different users) represents a larger savings than the reduced HTTP request overhead of combining all of the files into one.

If a browser is only ever executing a small percent of the total JS code base at any given time, then this would make sense. Because they have so many different users and different parts of different applications running in different configurations for those users, it is arguable that this is the case.

Second, those files only need to be downloaded once, then the browser won't ask for them again until they have changed or the cache has expired, so only the first visit really benefits from the all-in-one style. And yes having and advanced CDN with many edge locations around the world definitely helps.


Maybe they think it's more likely that you visit Facebook more often than you clear your browser cache.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号