Do you separate JavaScript functionality (aka Unobtrusive JavaScript)?

Last updated by Brook Jeynes [SSW] 6 months ago.See history

A website can be broken down into three main development parts: content, design and functionality. To optimize a website for search engines, it's important to separate the content  (crucial for search engines) from design and functionality (not important for SEO).

All JavaScript code should go into an external .js file (linked to the document with a <script> tag in the head of the page) and not embedded within HTML. The same should be done for CSS files. Don't bloat your HTML file and confuse search engines. Separate the legitimate content from what is programming code.

<a onclick="action()" href="#">Click Here</a>

Figure: Bad example - Never include JavaScript as inline attributes

<a href="backuplink.html" class="action">Click Here</a>

Figure: Good example - JavaScript (included in an external file) should use a class or id for its behaviours

We open source. Powered by GitHub