Instance: Write friendly JavaScript code whenever possible

Source: Internet
Author: User
Tags config

In search engine robot searches, the type,text/html for such "text" is the highest (except at this stage Text/xml), and text/javascript this kind of friendly degree is not ideal, If robot also wants to judge the DHTML code, the complexity is higher and is not zoned, so if you want to increase the friendliness of your code when you are programming with DHTML. A better approach would be to "simplify DHTML code to code that has no HTML as much as possible". How do you understand this sentence?


a JavaScript menu.
Method One, adopt the General programming method:
<script type= "Text/javascript" >
var navi_menu = Neverdhtmlmenu ();
/* AddItem method
* @ PID
* @ ID
* @ text
* @ href
Navi_menu.additem ("0", "1", "Home", "");
Navi_menu.additem ("0", "2", "blog", "Http://");
Navi_menu.additem ("0", "3", "Music", "Http://");
Navi_menu.init ("Navigator_container");
Second, the use of search engine more user-friendly programming methods <script type= "Text/javascript" >
onload = function () {
var config = {
Container:document.getElementById ("Navigator_container");
and more Configuration Code
var navi_menu = new Nevercssdhtmlmenu (config);
Navi_menu.init ();

<div id= "Navigator_container" class= "Navigator_menu" >
<li><a href= "Http://" >home</a></li>
<li><a href= "Http://" >blog</a></li>
<li><a href= "Http://" >music</a></li>
<!--more ...-->
From the method one and the method to compare, the method a few HTML encapsulated into the Neverdhtmlmenu (), but this does not have the actual benefit, although we can still put CSS into this class.
There are many benefits to be seen in method two, such as separating view from program and implementing MVC for the client. In other words, the development efficiency can be improved.

Some friends may ask, besides menu, what other programs can be separated by the above method?
Above also mentioned, the general interaction with the page more, will produce a lot of HTML, will affect the search engine robot, can use this method, of course, these just discuss the search engine friendliness, so, any code must be based on the actual situation.

Or ask a friend, why would this improve development efficiency?
For example, after the graphic is done, (assuming some of the relevant HTML written by the US Union) is followed by the XHTML standard (as shown above)
Suppose I want to change the original home to default page, then art and programmers to communicate, said to change the word of this menu, communication time in the development will be more. Therefore, in the development progress, this time should be counted. If you want to change the template, then you have to communicate. Or if the original use of JS generated HTML is a table made of menu, to be revised, then the program has to rewrite. Unfavorable to maintain ...

This method suggests that you can try, the main meaning is JS is responsible for business implementation, and view is still left to the HTML to deal with.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.