What is the real benefit of using external css and js in place of placing code directly in ... and in terms of page loading speed?
if we are controll开发者_JAVA技巧ing whole site from one header.php/aspx file? Is use of external files makes page loading faster?
My question is only related to page loading speed.
On a per-request basis (that is, looking at page load performance of JUST one page), speed-wise you actually take a small performance hit by separating the files. But when looking at performance, you get a performance boost when loading multiple pages that utilize the same JS or same CSS. In those cases, the content of the JS/CSS is only loaded once for all requests.
Although you didn't ask this as part of your question, it also helps code maintainability. If you make one change in your CSS and it gets loaded across multiple pages, if you embed the JS/CSS in the page then you have to make the same change across all of your pages.
External files can be cached, and have to be loaded only once even when referenced from multiple locations. This usually outweighs the performance hit caused by the one additional request when the resource is first loaded.
i know you asked about page load speed and from that standpoint id say the greatest benefit id say cacheing is a big advantage but i wouldn't break it into multiple external files (because like first answer said it takes time to make a request) but you also get a benefit from a SEO standpoint... crawlers will only index to a certain point in a page and keeping js and css out of the top lets them see content higher in the page
i just found this article where a guy did the tests
http://articles.sitepoint.com/article/indexing-limits-where-bots-stop
yes, the css and js files will be cached by the browser so they only get loaded once.
精彩评论