Tag Archives: Ajax

FireFox 4 does not like script.aculo.us builder

After upgrading to FF4 I noticed that some of my JavaScript, which had been working perfectly fine, stopped working. I was able to isolate the problem to the use of the script.aculo.us Builder class to create a script element, like so:

var head = $$("head")[0];
js = Builder.node("script", { type: "text/javascript", src: path });
js.onreadystatechange = function() { if (js.readyState == 'loaded'
  || js.readyState == 'complete') js.onload(); };
js.onload = function() { console.log("loaded!"); };
head.insert(js);

However, the onload event would never be triggered. In fact, Firebug indicates that the JavaScript file I’m trying to load is never actually loaded from the server. So it’s back to basics without using script.aculo.us’s Builder:

var head = $$("head")[0];
var js = document.createElement('script');
js.type = 'text/javascript';
js.onreadystatechange = function() { if (js.readyState == 'loaded'
  || js.readyState == 'complete') js.onload(); };
js.onload = function() { console.log("loaded"); };
js.src = path;
head.appendChild(js);

And guess what: this works. The file is loaded. Now why does this happen? The new script element is in fact added to the DOM; I can see that in Firebug. But it never loads the JavaScript from the server.

Playing around with script.aculo.us’s builder.js shows that the script tag cannot be created through innerHTML but must be created through document.createElement instead. I don’t know why script.aculo.us tries the innerHTML approach first, but it does – and it works. It just doesn’t load the javascript file. If I deliberately make the innerHTML approach fail, it falls back to document.createElement, which works.

This is not the whole story, though. When adding attributes to the newly created element, builder.js again tries to use innerHTML before using document.create. And again, skipping innerHTML to make it fall back to document.create works.

The reason innerHTML is used can be found here, according to the source, but I could not access this URL at the time of this writing.

Technical Aspects of Search Engine Optimization (SEO)

“So can you make sure that my new website appears in Google’s search results, on the first page?” It’s what clients tend to ask. They seem to think that one picks up the phone to have a little chat with Google to see if they can be persuaded to bump the site’s classification up a bit. No can do.

Nevertheless, there are ways and means to help Google classify your site properly – and higher. In the old days, it was commonplace to add a bunch of keywords in the META tags of a site in order for search engines to believe that the site was relevant to a lot of searches (the inclusion of porn-related keyword being a much-practised solution). Nowadays, however, Google all but complete ignores keywords. It’s better to leave out the META keywords altogether, since including irrelevant keywords will damage your reputation with Google rather than improve it.

In lieu of keywords, Google checks the actual content of your site (we’ll get to that in depth in a moment). It also checks the number of sites that link to yours (so-called backlinks). This number isn’t something you can improve overnight. Some social engineering is necessary to get other webmasters to link to your site. Link trading is commonplace: you link to my site, I link to yours. This is the most powerful way to get your site noticed by Google. Read more »