Wednesday

SEO for Ajax - Takling the Javascript First - Part 3

In this part, we will look into the main building blocks of Ajax and how to optimize them for Search Engine Optimization one by one. In fact, I will not get into details of the working of Ajax itself as it is beyond the scope of this writing. I will try to avoid going too much technical here, rather a simple and clean approach will be used to convey the concept and underlying impacts accordingly. After reading this “SEO for Ajax – part 3”, I hope it would become easier for an SEO expert to implement the items with the coordination of his development team members and architects.

JavaScript Optimization

There is a good amount of use of Javascript in Ajax, you should focus on improving your use of JavaScript to reduce your download footprint. Authors of such javascript libraries do understand the JavaScript bloat problem. They present their code in a standard, completely commented and maintainable version as well as in a minified version. You should have an understanding of minification and how it works. It is possible that there will be code outside your library that will require to be compressed as well.

Remove JavaScript Comments

You can safely get rid of all JavaScript comments that serves no purpose. As these add extra bytes to the code, so eliminate them from your code to reduce the overall size. These are indicated by // or /* */. They also offer no value to the end user and just add to file size. You also need to know the conditional commenting system of IE browser that is frequently used with “includes” or Cascading Style Sheets (CSS). You should not remove these conditional comments from your code because you may otherwise unintentionally break your Javascript. Fortunately, many advance tools for page optimization know this criterion, and will not flag that up.

String Constant Macros – A good approach

If you find in your code that their are repeating occurrences of strings or a complete strings over and over again, you can substitute a simple string macro using a global variable remapping can reduce a number of bytes. For example, if you have a number of alert( ) invocations in your program, like this:
alert("Record has been saved successfully");
you could set a global variable, like this:
message=" Record has been saved successfully ";
to serve as a string constant and then replace the recurring strings in the various calls as follows:
alert(message);
You can even show some extended messages based on the original macro as:
alert(message +": Please create a new record now");
There is one care with this technique. It is necessary that you make sure the string is used very often so that macro makes sense

What you need to do with Whitespaces

JavaScript ignores the white spaces so you can easily decrease the whitespace between operators. For example, instead of writing this:
var str = "Row number " +
x +
" has invalid date";

you can write this:

var str=" Row number "+x+" has invalid date";

Be careful when condensing, however. JavaScript treats line breaks as implicit semicolons.
If you do not finish lines with semicolons, you may find yourself in trouble and your code can mess up. For example, the following well formed JavaScript uses implied semicolons:
a=a+1
b=b+1
A simple whitespace remover tool might produce this:
a=a+1b=b+1
This code will throw an error. But if you add in the needed semicolons, the code will work:
x=x+1;y=y+1;

Avoid Constructs - Little reduction in Size

In many conditions, you can get rid of code and syntax constructs without hurting the
code. For example, given chunk of if statements and several loops that contain only a
single statement, you can remove the braces, so this:

if (isActive)
{
alert("You card is Active");
}

becomes this:

if (isActive)
alert("You card is Active");

As another size reduction example, you also can eliminate a return statement with no
argument just before the end of a function. So, this:

function doProcess( )
{
/* code here*/
return;
}

becomes this:

function doProcess ( )
{
/* code here */
}
There are also some good tools available out there that you can employ for byte saving tricks to tune code, but generally this tool is recommended for such things. http://www.w3compiler.com. All above techniques may only save a small portion of the total file size but every byte counts from SEO perspective. In fact, Google will consider loading time and fast response from server a major SEO factor to be considered in search result for year 2010. So never ignore anything which is helpful in reducing the file size on the client machine.

XML vs JSON – Choice is yours

Ajax requests may be tiny as compared to the conventional full post backs, but there definitely are differences with various data formats used with Ajax itself, particularly if you consider the included content vs. the structural markup. For example, consider that when a request is made with simple list of comma separated values, any returned data will be pretty concise:
value1,value2,value3,...value N
If you encoded the same data in XML, it would be much heavier:

<?xml version="1.0encoding="UTF-8?>
<docElement>
<package>Value 1</ package >
< package >Value 2</package>
...
< package >Value N</ package >
</docElement>

In the case of an Ajax based application, the data sent and consumed is often very small and is textual in nature, so it can be HTTP compressed plainly for transmission. XML primarily considered the fundamental part of AJAX is not considered a very good option from one school of developers and they are quite right in making that opinion. First, XML is bulky as compared to other lighter formats. Second, there is the too much DOM code that is required to deal with parsing out the response. Finally, because browsers generally are not behaving as validating XML parsers but instead focus only on well formedness, the semantic value of XML is rather wasted. As a replacement to XML, many Ajax developers favor to use JSON, available at http://www.json.org. JSON is a lightweight data exchange format that is based on a subset of the Javascript. Because it is a subset of Javascript, we can simply convert a JSON response into something that the receiving script can manipulate directly.

For instance, we may return as below, which is a valid JSON array:
["item1","item2","item3","item4"]

Or we may return a JSON object such as:
{"Status": "Active", "Amount" : "$5000" , "Expire" : "15/05/2010" }

If this were found in the responseText property of an XmlHttpRequest object, we might speedily make it accessible for use by means of below mentioned code:
var output = eval(xhr.responseText);

Now you would be able to reference the individual values in the output object as:
var str = "Status of card is " + output.Status + " and transaction amount is "+ output.Amount + ", Card will Expire on " + output.Expire;

OK, that’s enough for now, take a long breath and get ready for 4th and Final Part of this SEO for Ajax series.

60 comments:

  1. . You can easily procure Search engine optimisation services so that users find it easy to find your site. If you are looking out for companies that provide SEO services India based, there are a large number of companies like trafficwala.com which are sure to make your business grow. The actual trick is to discover the right kind of keywords for your kind of business so that you attract users who can be potential customers. This thing as it sounds is not difficult at all, you can use various keyword research tools available free of cost on the web and which results in producing product oriented keywords which will only be found at your site

    ReplyDelete
  2. Thank you for understanding the limits of your readers. Not all of us are very technical person when it comes to web designing, developing, XML codes and stuff. You’ve made the article simple and easy for us to understand.
    seo

    ReplyDelete
  3. more compatible one taht will suit to the site design and layout.
    ____________
    seo package

    ReplyDelete
  4. Author
    Thanks a lot for make this great blog.
    Please keep posting

    ReplyDelete
  5. Hi Frnds,
    I would like to give information about article website, where you can submit instant article. No need to resister. Just publish your article with single click. http://www.instantarticles.net
    Thanks & Regards
    Admin

    ReplyDelete
  6. yes thats nice information for us........

    Regards
    E-commerce

    ReplyDelete
  7. Quite informative post, will surely try to implement the process.

    Website Marketing Company

    ReplyDelete
  8. Hey all, I found a good site for those wondering about the intricacies of the dental school experience:seo marketing company

    ReplyDelete
  9. good news
    After reading your post, i think its a fresh news for everyone.

    ------
    Thanks
    SEO India

    ReplyDelete
  10. Very informative post. Thanks for sharing the code details too here very clearly. The explanation was so clear and concise. Definitely worth reading article for seo.
    Regards,
    seo company india

    ReplyDelete
  11. I have some Best Dofollow Social bookmarking which are really helpful in your keywords ranking


    http://www.web-promotion-services.info
    http://www.allbusiness-news.info
    http://www.your-bookmarks.co.cc
    http://www.submityourstory.co.cc
    http://www.diggyourstory.co.cc
    http://www.123webs.co.cc
    http://www.twitterbookmark.co.cc
    http://www.1stgreatnews.co.cc
    http://www.usa-bookmarks.co.cc
    http://www.123-news.co.cc

    ReplyDelete
  12. doing seo for Ajax website is little hard, but the tips describe in the post are very effective and i think that will work. Thanks

    ReplyDelete
  13. Wow, one of the best read posts so far.

    ReplyDelete
  14. Nice Commenting, i want to appreciate u that u have share right information about SEO optimization Services and different type of services regarding SEO

    Thanks
    SEO Services India

    ReplyDelete
  15. Hi,

    Thanks for sharing the whole information and this is very useful for us.

    San Francisco SEO

    ReplyDelete
  16. I read this post. It looks interesting. Please keep posting.

    ReplyDelete
  17. use gzip to compress js script is also a good way.

    seo tips

    ReplyDelete
  18. This is really a nice blog. It helped me to get valuable informations. I really appreciate.

    ReplyDelete
  19. Great Post, Very Informative.

    Keep Up The Good Work!

    Best Regards.

    ReplyDelete
  20. great work .. goood job.. i liked the layout of your blog very much. you can get free seo tools and domain name along with web hosting at www.hostdomainshere.com.

    ReplyDelete
  21. I was looking for information about SEO and ur blog is great, ur post is great, it's clear, helpful and so interesting. Good job!

    ReplyDelete
  22. Well, the SEO information which you have given is very good, i have the same SEO material blog. Hope this will help to the SEO beginners.

    ReplyDelete
  23. Great post, this article contains how marketing should be done, will save post and share. affordable seo

    ReplyDelete
  24. Really informative, the Javascript part was an interesting fact to know.

    Website Designing

    ReplyDelete
  25. it's really nice post.i think new days going to make a stable seo technique like link building....

    ReplyDelete
  26. I can see that you are an expert at your field! I am launching a website soon, and your information will be very useful for me.. Thanks for all your help and wishing you all the success.

    ReplyDelete
  27. nice article.......
    by this i got some knolodege on that.....
    yhanq u .......
    keep going

    ReplyDelete
  28. "Seo information blog"
    this blog contain good information..
    by going through ur blog i was able to learn many new things........
    thanq u...

    ReplyDelete
  29. Great post! You have some brilliant contents!

    ReplyDelete
  30. It is great to read some of the information and feedback, here. I hope to read more ideas in the future!!!

    ReplyDelete
  31. I recently came across your blog and have been reading along. I thought I would leave my first comment. I don't know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often.

    ReplyDelete
  32. Thank you for understanding the limits of your readers. Not all of us are very technical person when it comes to web designing, developing, XML codes and stuff. You’ve made the article simple and easy for us to understand.
    seo

    ReplyDelete
  33. I absolutely loved the book. It was unpredictable, very visual and it was unique. Although I find the author a little bit odd, (He blogs about the weirdest things) The Maze Runner was amazing. Thanks ;)

    ReplyDelete
  34. Thanks for the post. It is very informative. I get to know various things from this post. Keep posting like this.

    ReplyDelete
  35. Really great and informative post by you... i appreciate your effort taken for the same.

    Thanks For Sharing.
    SEO Freelancer India

    ReplyDelete
  36. doing seo for Ajax website is little hard, but the tips describe in the post are very effective and i think that will work. Thanks

    ReplyDelete
  37. Really your information is very helpful for everybody who work of seo.It's a great job.

    ReplyDelete
  38. On-site optimization basically has anything to do with actual website. When people talk about on-site optimization they referring to few things. First needs to coded correctly and pass w3c validation.

    site optimization

    ReplyDelete
  39. Great post!. It's clear, helpful and so interesting.

    ReplyDelete
  40. hmmm very interesting though , helpful in the sense to understand the programming aspect of seo optimization..............

    ReplyDelete
  41. Very good article, If any company follows these steps than it would become easier for an SEO expert to implement the items with the coordination of his development team members and architects. Also, the use of coding had helped us understand your point in a very precise way.

    ReplyDelete
  42. Wow! Very informative blog you have shared, doing seo for Ajax website is little hard, but the tips describe in the post are very effective and i think that will work. Thanks

    ReplyDelete
  43. Really nice and honest advice! i love it, absolutely brilliant.....

    ReplyDelete
  44. Thanks a for this informative post. this mistakes looks small but create big problem to search engine so always be careful while constructing websites.....


    Smith ALan

    ReplyDelete
  45. Ajax is very helpful SEO techniques.

    Thanks

    ReplyDelete
  46. Thanks for the great post..waiting for your next post....

    ReplyDelete
  47. Is there any tools available for Javascript optimization?

    ReplyDelete
  48. Hi,

    I have read your many posts and found all interesting and helpful. Thanks for this awesome article.

    Regards
    SEO Boston

    ReplyDelete
  49. This is a really good read for me. Must agree that you are one of the coolest blogger I ever saw. Thanks for posting this useful information. This was just what I was on looking for. I'll come back to this blog for sure! I bookmarked this blog a while ago because of the useful content and I am never being disappointed. Keep up the good work

    ReplyDelete
  50. Once i started reading this article i could not stop as got a lot of useful info for my future work.

    ReplyDelete
  51. I wanted to thank you for this great read!! I definitely enjoying every little bit of it I have you bookmarked to check out new stuff you post

    ReplyDelete
  52. Creating a Javascript object is VERY DIFFERENT from the way it is done in languages like C++ or Java. This very approachable introductory tutorial illustrates the very dynamic - and startling to the uninitiated - syntax for creating Javascript objects. A MUST READ to avoid confusion.Thanks.:)

    ReplyDelete
  53. Thanks for the information provided by you is so useful and very informative for Javascript optimization.

    ReplyDelete
  54. I learn a lot from this post. Its so amazing post. There are multiple costs to non-compliance, including financial, both personal and societal, and physical. 

    ReplyDelete
  55. This was such an interesting article, great read.

    ReplyDelete
  56. The ideas are fantastic and the key things you said in truth,many comments are right and I think you should be better,and good luck in your life.

    ReplyDelete
  57. I am extremely pleased for this great read, I definitely enjoying every thought.

    ReplyDelete
  58. Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this subject.

    ReplyDelete