Search Engine Optimization Tip 19: Move JavaScript to External File

This is search engine optimization tip number nineteen in our continuing series of tips from search engine optimization company Vizion Interactive. All of our search engine optimization tips meant to be very specific, they should not take a lot of time to fix or review (to check to see if you are following the search engine optimization best practices), and will be rather “short and sweet” and directly to the point. In fact, this search engine optimization tip is short: it’s about what I would call “code bloat”. You do not want to have fat web pages that are full of code. For SEO purposes, we want thin web pages: pages that are light on code.

seo-tip-19-fat-code-web-page.jpg Not following along with our Search Engine Optimization Tips? Our last search engine optimization tip, search engine optimization tip 18, was about linking within sentences. The SEO tip before that, search engine optimization tip 17, was about links and your reputation and finding additional links to your site by searching at your favorite search engine for your name or your company name. The SEO tip before that was about creating a breadcrumb trail on your site. To find the previous search engine optimization tips, take a look at one of my previous SEO tips; you should find some links there. All of these “search engine optimization tips” are things I look at when analyzing a site or optimizing it for the search engines. Keep in mind, though, that this is only the beginning. There are a lot more search engine optimization tips coming in the future. In fact, to keep up with these SEO tips you might want to subscribe to our SEO RSS Feed.

For this search engine optimization tip, let us talk about all of the excess code that is on your site. Our tip is to move that code (specifically the JavaScript code) to an external file. In other words, we want to make our html pages smaller in size, thus putting more focus on the actual content on those web pages: the content that matters to the search engines.

If you take a look at your html code you may JavaScript code in there. That JavaScript code takes up valuable real estate in your html file. Rather than putting all of the code into the html file itself, you can move that code to a text file (also called a .js file) and “call the file” in your html code. Doing this will not change any of the functionality of your web site. In fact, you will not notice any changes when you view your web page. However, the html file itself will not have as much “code” on it. Here is how to move your JavaScript code to an external JavaScript file:

  1. First, you need to evaluate whether or not you have the technical expertise to actually move the JavaScript code to an external JavaScript file. If you’re not that technical, then you might want to outsource this task to someone who is more experienced at doing this. (By the way, if you need help doing this feel free to contact us and you can outsource this task to Vizion Interactive.)
  2. The next step is to identify the actual JavaScript code that needs to be moved. Generally speaking, you will want to look for a the code. It will start with:
     

    and end with . Essentially, you’ll want to copy everything (including the script and ending with script) and save it in a text file named something.js (whereas something in the filename describes what that script does. The filename doesn’t really matter, but naming it with a memorable name will help you in the future.

  3. Once you copy the JavaScript code out of your html file and saved it into a file called something.js you will need to get rid of the code on your html page and “call the file” instead. So, if you’ve copied the code you can delete it in your html file.
  4. Upload or save the something.js text file on your web site somewhere. Some prefer to make a new folder or directory specifically for the external JavaScript files, but they really can be saved anywhere on your site. As long as you remember where they are, you can call them in the html file.
  5. In the html code where the JavaScript used to be, you need to call the file. You can do it just like this:
    &ltscript type="text/javascript" src="http://www.domain.com/assets/js/something.js"></script>

That is the code for “calling” your JavaScript file named something.js in a folder called javascript.

After you have saved your html file, go to that web page on your web site. The code will have been moved out of your html page and your html pages won’t suffer from what I call “code bloat” which ultimately hurts your search engine optimization. The more you can focus the content in your html files the better.

  • Hi Bill Hartzer,you have given a very good tip.Even i observed that web pages with light code will have good page rank.Many of the seo's don't know this tip.Thanks for a good tip.

  • SEO Specialist

    Good day,

    This tip would greatly help those who have javascript in their sites. We all know that javascript is one way of creating a non-boring page for users. It would also attract them to come to your site more often if they are interested.

  • It's always a good idea to improve the code-to-content ratio.