2

If JavaScript and CSS files were included inside of pages it would cut down the number of http requests and therefore make the page load faster. I feel like I am missing something because it seems like any organization interested in lightning-quick pages would do this. However, I don't recall any sites having tons of CSS and JavaScript into their pages as I look at the source code.

Questions:
What errors are in my statements above?
What are the drawbacks of this approach (shown in the title via psuedocde)?

1
  • Check out Google Minify as it will let you combine your css and js files as well as minify them on the back-end. Really speeds up performance on our websites. Commented Jul 4, 2011 at 21:07

3 Answers 3

4

If the data is in an external file it can be cached and reused on other pages (or the same page, revisited) without having to fetch it over the network again.

You get a minor performance penalty on the first page in exchange for a major performance enhancement on subsequent pages.

Sign up to request clarification or add additional context in comments.

Comments

0

Modularity is a major concern:

I can pick and choose which javascript and css files I want per page: otherwise I'd have a ton of css and javascript files that have all the different configurations (which is just messy).

I can also cache a file and hand it to someone else faster

Where you will find an example of this happening is when sites chuck their images together into one png file and then use css to slice up the bits they want for buttons etc.

Comments

0

Another aspect not only for inline css and jscript. When I write code I hate to repeat. It leads to errors is difficult to maintain (update/edit) and a waste of time and space. Printing CSS or jscript once in a file that gets downloaded once is less error prone, easy to maintain and less waste of time and space.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.