Optimise Magento CSS & JavaScript Links
Things in life are much better when they’re local. A local supermarket is better than one 10 miles away. A local pub is even better than that. These values should also be applied to Magento websites, though I wouldn’t recommend building websites in the pub… Following on from Luci’s excellent post about making the CSS and JavaScript links local, I’d like to show an alternative which does exactly the same thing. Why you ask? Only a very small reason I answer. Running a str_replace command on a file that is loaded directly on the frontend by the server will slow the load time, though only fractionally. The way round it is to carry out the hacks at an earlier stage, deep in the murky depths of the Magento core PHP…
1. Find the file: app > code > core > Mage > Page > Block > Html > Head.php
2. Copy this file into your local directory (app > code > local > Mage > Page > Block > Html > Head.php)
This local file will now be given priority over the core file. Remember to never change core files!
3. Open this file and go to line 248. Remember this line number may change in future versions, anyway you’re looking for this line of code:
$items[$params][] = $mergeCallback ? Mage::getBaseDir() . DS . 'js' . DS . $name : $baseJsUrl . $name;
Simply change the part where it says $baseJsUrl to ‘/js/’, so your new line of code will look like this:
$items[$params][] = $mergeCallback ? Mage::getBaseDir() . DS . 'js' . DS . $name : '/js/' . $name;
4. Now shoot your way up to line 220, time to reposition our str_replace. Find the line which looks like this:
return $html;
Just wrap the str_replace around the html variable, which is responsible for bolting your domain URL onto the front of your CSS links. Notice how I put the src=\” part in front of the url? This mean that it won’t mess up the canonical links tag. Then it will look something like this:
return str_replace("src=\"http://www.domain.co.uk/", "src=\"/", $html);
Regardless of which method you use, you’ll be left with links in your header that are much shorter and neater thus improving your website’s overall SEO. Thanks for reading the Magento blog at Ecommerce Web Design. If this blog post has helped, or there’s something you’d do differently, let us know by posting a comment below!

On the day where Amazon have dedicated virtually their entire homepage in homage to the latest version of it’s Kindle device, I thought it is perhaps appropriate to draw attention to this impressive piece of hardware. No doubt Apple’s iPhone and iPad have turned up the heat on Amazon’s development of the Kindle, and as such the new release comes with a host of new features:


