Rules

Secret ingredients to quality software

Edit
Info

Do you separate JavaScript functionality (AKA Unobtrusive JavaScript)?

Last updated by William Yin on 24 Aug 2015 01:08 am (over 5 years 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: 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

Tiago AraujoTiago Araujo

We open source. This page is on GitHub