admin管理员组

文章数量:1026639

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

Facebook is obviously a very plex application and I can understand how such modularity 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?

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

Facebook is obviously a very plex application and I can understand how such modularity 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?

Share Improve this question asked Sep 28, 2011 at 2:59 Lea HayesLea Hayes 64.3k16 gold badges69 silver badges118 bronze badges 1
  • Most Facebook users that I know are on all the time, so it wouldn't matter where the scripts and stylesheets are downloaded from because they'll be in the browser cache. – nnnnnn Commented Sep 28, 2011 at 3:08
Add a ment  | 

3 Answers 3

Reset to default 5

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 es down in a bunch of small files.

They might be running into the case where the savings of being able to serve different binations 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 bining 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.

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

Facebook is obviously a very plex application and I can understand how such modularity 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?

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

Facebook is obviously a very plex application and I can understand how such modularity 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?

Share Improve this question asked Sep 28, 2011 at 2:59 Lea HayesLea Hayes 64.3k16 gold badges69 silver badges118 bronze badges 1
  • Most Facebook users that I know are on all the time, so it wouldn't matter where the scripts and stylesheets are downloaded from because they'll be in the browser cache. – nnnnnn Commented Sep 28, 2011 at 3:08
Add a ment  | 

3 Answers 3

Reset to default 5

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 es down in a bunch of small files.

They might be running into the case where the savings of being able to serve different binations 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 bining 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.

本文标签: javascriptWhy doesn39t Facebook combine its CSSJS filesStack Overflow