tags:

views:

708

answers:

8

We have an SEO team at my office, and one of their dictums is that having lots of <script> blocks inline with the HTML is apocalypticly bad. As a developer that makes no sense to me at all. Surely the Google search engineers, who are the smartest people on the planet, know how to skip over such blocks?
My gut instinct is that minimizing script blocks is a superstition that comes from the early ages of search engine optimizations, and that in today's world it means nothing. Does anyone have any insight on this?

A: 

What's wrong with Script blocks?

Registered User
A: 

per our SEO guru, script blocks (especially those that are in-line, or occur before actual content) are very, very bad, and make the google bots give up before processing your actual content. Seems like bull to me, but I'd like to see what others say.

Danimal
+2  A: 

I don't know about the SEO aspect of this (because I never can tell the mambo jambo from the real deal). But as Douglas Crockford pointed out in one of his javascript webcasts the browser always stops for parsing the script, at each element. So, if possible, I'd rather deliver the whole document and enhance the page as late as possible with scripts anyway. Something like

<head>
    --stylesheets--
</head>
<body>
  Lorem ipsum dolor
  ...
  ...
  <script src="theFancyStuff.js"></script>
</body>
VolkerK
+11  A: 

It's been ages since I've played the reading google's tea leafs game, but there are a few reasons your SEO expert might be saying this

  1. Three or four years back there was a bit of conventional wisdom floating around that the search engine algorithms would give more weight to search terms that happened sooner in the page. If all other things were equal on Pages A and B, if Page A mentions widgets earlier in the HTML file than Page B, Page A "wins". It's not that Google's engineers and PhD employees couldn't skip over the blocks, it's that they found a valuable metric in their presence. Taking that into account, it's easy to see how unless something "needs" (see #2 below) to be in the head of a document, an SEO obsessed person would want it out.

  2. The SEO people who aren't offering a quick fix tend to be proponents of well-crafted, validating/conforming HTML/XHTML structure. Inline Javascript, particularly the kind web ignorant software engineers tend to favor makes these people (I'm one) seethe. The bias against script tags themselves could also stem from some of the work Yahoo and others have done in optimizing Ajax applications (don't make the browser parse Javascript until is has to). Not necessarily directly related to SEO, but a best practice a white hat SEO type will have picked up.

  3. It's also possible you're misunderstanding each other. Content that's generated by Javascript is considered controversial in the SEO world. It's not that Google can't "see" this content, it's that people are unsure how its presence will rank the page, as a lot of black hat SEO games revolve around hiding and showing content with Javascript.

SEO is at best Kremlinology and at worse a field that the black hats won over a long time ago. My free unsolicited advice is to stay out of the SEO game, present your managers with estimates as so how long it will take to implement their SEO related changes, and leave it at that.

Alan Storm
+1  A: 

I've read in a few places that Google's spiders only index the first 100KB of a page. 20KB of JS at the top of your page would mean 20KB of content later on that Google wouldn't see, etc.

Mind you, I have no idea if this fact is still true, but when combine it with the rest of the superstition/rumors/outright quackery you find in the dark underbelly of SEO forums, it starts to make a strange sort of sense.

This is in addition to the fact that inline JS is a Bad Thing with respect to the separation of presentation, content, and behavior, as mentioned in other answers.

Brant Bobby
+2  A: 

There's several reasons to avoid inline/internal Javascript:

  • HTML is for structure, not behavior or style. For the same reason you should not put CSS directly in HTML elements, you should not put JS.
  • If your client does not support JS you just pushed a lot of junk. Wasted bandwith.
  • External JS files are cached. That saves some bandwith.
  • You'll have a descentralized javascript. That leads to code repetition and all the known problemns that comes with it.
Marcio Aguiar
+1  A: 

Your SEO guru is slightly off the mark, but I understand the concern. This has nothing to do with whether or not the practice is proper, or whether or not a certain number of script tags is looked upon poorly by Google, but everything to do with page weight. Google stops caching after (I think) 150KB. The more inline scripts your page contains, the greater the chance important content will not be indexed because those scripts added too much weight.

hal10001
A: 

I've spent some time working on search engines (not Google), but have never really done much from an SEO perspective.

Anyway, here are some factors which Google could reasonably use to penalise the page which should be increased by including big blocks of javascript inline.

  • Overall page size.
  • Page download time (a mix of page size and download speed).
  • How early in the page the search terms occurred (might ignore script tags, but that's a lot more processing).

Script tags with lots of inline javascript might be interpreted to be bad on their own. If users frequently loaded a lot of pages form the site, they'd find it much faster if the script was in a single shared file.

Matt Sheppard