Categories
SEO Web optimization Wordpress

WordPress: bringing a site from the ground up

These are the must haves, if you want your blog to be successful, and problem free

1) Active your Akismet plugin

2) Install Google Analitycs for WordPress from the get go.

3) Ditto for SEO.  Here’s a good plugin: http://wordpress.org/extend/plugins/seo-ultimate/

4) Subscribe to the following free auto-listing and update services (under “Settings / Writting”):

http://codex.wordpress.org/Update_Services

This usually ping the search engines to start indexing your site, but don’t count on it for that.

5) Generate a google site map, to let google know about your pages. Plugin: google XML Sitemaps http://wordpress.org/extend/plugins/google-sitemap-generator/

Categories
SEO

SEO guidelines

  1. Submit your site to the major search engines for indexing:
    1. http://www.google.com/addurl/
    2. http://search.yahoo.com/info/submit.html
    3. http://www.bing.com/docs/submit.aspx
  2. Check that your robots.txt file is correct and not preventing crawlers from getting into your site: http://www.robotstxt.org/
  3. Use Video and Flash sparingly, and knowing it doesn’t get indexed by crawlers
  4. Promote important content to home page, and make sure there are clean links from the home page to your site’s key content.
  5. Avoid duplicated content.
    1. If two or more urls on your site are pointing to the same content, use Canonical Urls as follows (to indicate the page to be indexed):  <link rel=”canonical” href=”http://example.com/original_content_here”>
    2. Use plugings for CMS packages to avoid this problem: http://yoast.com/wordpress/canonical/, http://yoast.com/tools/magento/canonical/
  6. Use friendly URLs with keywords about your content on it. It is ok to use the “-” sign to separate words.
  7. Use Meta tags to describe your page content.
  8. The page title is really important, make sure you choose one with keywords about your content as well.
  9. H1 headings: as important as page title, h2-h6 not as important but also take them into account.
  10. The first 100 words of your content carry more weight than the rest, use them wisely.
  11. For images, use descriptive image names, as well as good alt tags for them.
  12. The following online tools could help:
    1. http://www.google.com/insights/search/#
    2. http://www.seomoz.org/term-extractor
Categories
PHP Programming

OOP Best Practices and architecture

  1. When creating classes, make a really general abstaction of the object you have in mind (usually an abstact class or interface), and then start working your way down to the specifics using inheritance, encapsulation and polymorphism. For example: to create a book object for an ecommerce site, create something like Product / Item / Books / Book.
    • Advantages: This way your architecture can accomodate other objects later (cars / clothes / other categories)
    • Inside your classes, you avoid using hard to maintain “If” flags and clauses to perform different tasks per type of class
    • At the same time, you maintain a hierarquical structure of your objects that help you control variables and methods per level.
    • Make sure your classes are not overloaded with responsibilities. Spread responsibilities around the hierarquical structure of classes, if you can’t define a class responsibility with 25 words, and without using “and” and “or” words, you may be overloading your class with tasks. This will be hard to maintain.
    • But always remember: OOP best practices are not set on stone. If you have a good reason to bend the rules (performance, etc), do it, but think hard before you go ahead.
  2. As a general safety rule, you can set all methods and variables to private, and start resetting them to protected or public as you go along.
  3. Add error handling to all places things can go wrong (unexpected input / output usually). See PHP Error Handling section for more details, but basically extend the provided Exception class with a new class for each kind of error, and at the catch part of your try catch statement, have several catches that will deal with the particular error the proper way based on Exception type detection.
  4. Here are four possible indications of design problems:
    1. Code duplication: if you get a deja vu feeling at code writing a class, think: if I change something fundamental in this routine, will the other simmilar routine need ammendments? If so, then you may have a dup class you can compress in one.
    2. If a class depends too much on Globals variables and its context, this class will be hard to maintain. Try to make each class its own environment.
    3. If a class is doing too much, think of ways to reduce responsibility and extend down to other classes.
    4. Testing for the same condition with “if” statements throughout diffent classes may call to review your polymorphism. Where you can do the “if” test once, and spawn different objects with no “if” conditions down that fork
  5. Inside your classes, seek for those lines of code that express variation and fork the behavior of the current class given different values or conditions, and try to encapsulate them in their own type class.
  6. The golden rules: “Do the simplest thing that work”, and “are you sure you are going to need this extra complexity?”
  7. Avoid global variables like the plague, they make your classes highly coupled with the system, can’t be reused easily, and it’s hard to encapsulate stuff when using those. If you are to use Globals (say, to avoid passing too many variables or objects around) use singletons instead.
  8. Use phpDocumentor to add documentation to your code, even the default, do nothing and just run it option is better than nothing: http://www.phpdoc.org/
  9. Make sure you include Unit testing with PHPUnit
Categories
Contracting

Contracting best practices

  1. Backup the client’s data before you touch their database or any other component that can be backed up.
  2. Save a working copy of their current code as well so you can easyily revert back in case of problems.
Categories
JavaScript

Javascript Performance and best practices

The following tips can be used to improve sluggish javascript code:

  • Avoid using the eval() function.
  • Avoid the with construction.
  • Minimize repetitive expression evaluation.
  • Use simulated hash tables for lookups in large arrays of objects.
  • Avoid excessive string concatenation.
  • Investigate download performance.
  • Avoid multiple document.write() method calls.
  • Use global namespace variables to encapsulate your variables, to avoid colisions with other JavaScripts
  • Recursion, as elegant as it is, is heavy in js, and it takes longer to execute than regular for or while loops. It can produce stack overflows. Use it lightly.

Source (for more details on why): http://www.devarticles.com/c/a/JavaScript/More-on-Variables-Functions-and-Flow-Control/3/

To check your JavaScript code for best practices you can use jlint:

http://www.jslint.com/

More lessons learned in the trenches:

  • When you user JS to switch classes, the DOM has to redraw and recalculate all the CSS associated with that and the children tags. Try to do it lightly, or try to stick to switching styles as inline inserts, Jquery animations style
  • When you need to use setTimeOut, use requestAnimationFrame instead. In a nutshell, it is a way for browsers to give you access to the frames when they refresh stuff, so your updates to the UI will be coordinated with other animations and things going on the UI. Here is an easy to digest example of this usage (or more complicated at the original source https://gist.github.com/1579671 ):
 window.requestAnimFrame = (function(){
      return  window.requestAnimationFrame       || 
              window.webkitRequestAnimationFrame || 
              window.mozRequestAnimationFrame    || 
              window.oRequestAnimationFrame      || 
              window.msRequestAnimationFrame     || 
              function( callback ){
                window.setTimeout(callback, 1000 / 60);
              };
    })();
Categories
HTML

h1 tag

Use one per page (ideally), this is your main title.