Forum Moderators: open
If I have a PILE of java sript in an external file ie x.js, which is called from my html code via:
<script language="JavaScript" src="x.js"></script>
<script language="JavaScript">myFunctionFromJsFile();
</script>
Will a spider travel to x.js and try to index what it finds in there or will the spider only see the code within the html file itself.
I am new to seo and am trying to learn how to minimize my html code size.
Regards,
Michael
here's a link:
[w3.org...]
First off, thankyou for answering my question and for the code advise. Secondly, why would anyone want to hide their java script and/or include external .js files as opposed to just embedding all the java code within the html code, if a spider is not going to index it anyway?
Regards,
Mike.
Putting your js code in an external file keeps the html size to a minimum.
The other major benefit of using external files is now you can control all of your javascript with one file. If it were on page and was used throughout the site, anytime you make a change, you need to use the find and replace routine.
Another advantage is that visitors will experience faster page loads as they move around your site. The first time they view a page that includes the file, the loading time will be whatever it needs to be, but subsequent pages will load a bit faster because the .js file will already be in cache.
I like external .js files for things like drop menus, newsletter signup boxes and search boxes that appear on multiple pages. Try to provide an alternate path to the information contained in the .js files for the benefit of users surfing with javascript turned off.