Home
Do you separate JavaScript functionality (AKA Unobtrusive JavaScript)?
  v5.0 Posted at 24/08/2015 11:08 AM by William Yin

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: Never include JavaScript as inline attributes

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

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

Related rules

    Do you feel this rule needs an update?

    If you want to be notified when this rule is updated, please enter your email address:

    Comments: