views:

145

answers:

6

We've built what is called a one page web app(a single html page + ajax)
In the pursuit of shaving as much http calls as possible, we bundled the JS and CSS in 2 files.

Meanwhile we took a look at the way Google Buzz for mobile is built and there are some interesting points:

  • inline SCRIPT and STYLE
  • no external JS and CSS
  • data:images in CSS instead of url(...)

Thus we went further and "inlined" the 2 JS and CSS files in SCRIPT and STYLE tags. Removing 2 precious http calls.

Anyone experienced some troubles doing that on desktop browsers ?

I'm not trying to open a religious debate about unobtrusivity ;) It is about performance, network latency, mobile pages, etc...

A: 

Inlining and linked CSS and script files are equivalent. There's no difference other than the HTTP gets.

David Pfeffer
Other than maintaining the spaghetti.
Tom
And the caching (as mentioned elsewhere)
ck
@Tom, If you have already a script that bundle the JS/CSS files, adding a logic to inline them is fairly easy.
Mic
@ck, the caching is not an issue, as the html page is cached and change at the same rate as the CSS/JSS it is not a content site, but a web app
Mic
+1  A: 

Never. Put them in the html head so they load first and don't fret.

Jage
Intrigued by all these talks, I've re-read the YSLOW pages, and they say reducing http calls is the most significant improvement for your first time visitors and the 40-60% of people who come with an empty cache on your site. They have as well an inline vs. external JS/CSS paragraph, which looks to favor inline in the case on one page apps. http://developer.yahoo.com/yslow/help/index.html
Mic
@Mic Interesting. I can definitely understand your argument - I just think that it is important to keep in mind that what works for Google won't always work for everyone else. But if it's working in your case then great.
Skilldrick
A: 

Is performance a problem you currently have? What Google does to support 100ks of concurrent users isn't necessarily what you should be doing. I've found it much easier to maintain code when things like CSS and JavaScript are kept in separate include files. I only break what I consider good coding practices when there's a compelling reason. It's hard to imagine a one-page app is being killed by traffic for two include files that will be cached by user browsers after first use.

Tom
And your bandwidth costs go up, as it won't use a cached css, js, or image any longer and instead download all that data over and over
Chad
Even if you have 2 users, the impact you leave if you have a really fast app is priceless. Especially on mobiles and high latency connections.
Mic
@chad, the inline files are in the html page that is cached
Mic
@Mic, you said "app" a static html page is not an "app".
Chad
@chad, An html page full of JS that calls a server can be an app, why do think it isn't?
Mic
@Mic, I suppose, if it's loaded with JS, but then if you're making all these server calls while running the site, what's a couple more to get the JS and CSS at the start?As a side note, new browsers no longer limit to 2 connections, so while you may have fewer connections to make by combining them, your browser will quite likely download the three files simultaneously faster even with the overhead of a new connection.
Chad
@chad, It is to reduce the effect of the network latency and give the user a screen as quick as possible even on a mobile. I think it is important for the initial impression and the day to day usage, but from the comments received, I'm may be too extreme...
Mic
@Mic, but it's not really quicker overall is it? If it caches the css and js files separately, they aren't downloaded every time the app is used, only when they change. Reducing the cost per load when they don't change by their size. By including them inline, you force the mobile browser to download MORE than is required each time they use the app.
Chad
@chad, the page has no dynamic content the HTML is as static as the JS/CSS and is cached the same way. But this is obviously not applicable for multi pages or pages with a dynamic content.
Mic
+2  A: 

Virtually no-one has to deal with the traffic Google do. I'd say it's virtually never worth following Google's lead in optimisations, because they just don't apply in the real world.

Skilldrick
It is not about traffic, but user experience that starts even when you beta test your app.
Mic
Yes, but the kind of optimisations Google make generally won't be noticeable. If Google trims 0.5% off the processor usage of each search, they could power a small country with the electricity they saved (I made that up). 0.5% isn't going to affect your user experience.
Skilldrick
Putting inline the 2 files, made a noticeable response time difference, especially on the mobile. So yes it is user experience.
Mic
Define "noticeable". Do you have performance stats or are just eyeballing it?
Tom
It was a gradual reduction from 17 calls to 3 and now 1 (the page). There is no need to measure, you can just see it.
Mic
Like how we could tell the Titanic was unsinkable. I'll stick to measurable effects.
Tom
Titanic, powering a small country,... nice talks.
Mic
+2  A: 

It is worth noting here that inline CSS <style/> blocks trump linked CSS files when there is a conflict.

For example

<style type="text/css">
  div .whiteBG {
    background-color: #fff;
  }
</style>

trumps a linked CSS file containing

  div .whiteBG {
    background-color: #ccc;
  }

even if the linked files are called last.

Robusto
That's interesting, even if you put an !important? But since we removed all external CSS, we are safe from this potential trouble.
Mic
@Mic: No, that's not what I said. For identically weighted selectors, the renderer will prefer inline to external. If you have !important on both, the inline one still wins.
Robusto
A: 

I think you are over looking the fact that nobody actually coded the output you see with a system like Google Buzz, or Gmail. They depend on a very very sophisticated system that have built on Python and C to compile the source and make it very friendly to there homegrown "push" system they have.

I dont think you should be as concerned with the output as being multiple requests, I think that issue is totally secondary to being able to build and deploy your app. Later focus on plopping all your JS and CSS in the head, as this can be done pragmatically when you deploy.

Joseph Silvashy
The sources are in many external JS and CSS, it is just when we bundle them(automatically with a script) that we added an easy extra step.
Mic