2

Just on the basis that best practices tell us to favor external CSS and JS files over inline HTML for performance advantages.

Is it a good idea to deliver as small an HTML file as we can manage? And use Javascript / jQuery to render as much of the DOM as we can, hook up Javascript events, etc. on the client side?

1
  • 1
    i don't know about performances but i like to do so, because this way i can implement javascript controlers. (as in "mvc") Commented Apr 15, 2013 at 0:40

2 Answers 2

2

The reason to keep CSS and JS in separate files has nothing to do with performance. If anything it can slow down your page because of additional roundtrips to the server.

The real reason is that for a web page (application) of any complexity it is extremely important to keep the logical structure of your page (declarative HTML) separate from the layout (CSS) and from the UI logic (Javascript).

Performance issues can and should be addressed separately using caching, minification, etc.

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

3 Comments

mfeingold and Kenneth, what about sites like this? developer.yahoo.com/performance/rules.html That imply external CSS and JS are faster due to better use of caching. This also isn't an uncommon belief among engineers I know.
It's true that you can cache CSS and JS, but also HTML. In terms of download speed, just try to send the smallest possible files to the client. We're talking about two different "speeds" here: the download speed of the content, and then the render speed on the client
@S.Valmont This is true, but it is beside the point. There is a ton of considerations when you structure your webpages, and the approach will differ based on how dynamic you site is and how often do you expect it to change. Regardless of anything your main enemy is not speed, it is complexity. Anything you can do to reduce complexity will help. Every time you increase complexity for the sake of performance or anything else - you are sooting yourself in the foot
1

In general, giving the browser the HTML is faster.

Of course, everything depends on how long the server takes to create this HTML.

But in terms of client-side rendering, a pre-built HTML will always win over a javascript generated document. This is because the DOM-API is relatively slow (although a lot of improvements have been made lately).

The separation of CSS and JS is more related to maintainability and SEO.

2 Comments

"The separation of CSS and JS is more related to maintainability and SEO" <- SEO has nothing to do with it, only maintainability and file sizes.
Not really true, Google definitely ranks pages with clean HTML higher than HTML with javascript in between

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.