jQuery Plugin Development Tips

Make Sure Your Plugin Naming is Unique - All naming conventions in your plugin, including it’s name, class and id’s should be as unique as possible to avoid conflicts with other CSS and JavaScript code and more important other jQuery functions.

Keep Your Code Separated - Avoid as much as possible mixing your CSS and JavaScript code. You never know what a developer may want to modify, so it’s best to keep these things in their respective files.

Please NO Hard Coding - This is the most frustrating thing to come across in any plugin you use. A hard coded file path in the JavaScript code that assumes you will be using the root path or something. Image paths can all be set in the CSS using background images, and paths in the code should all be written relative to begin with.

Your jQuery Plugin Should Work Out of the Box - Anytime a developer uses your plugins there should always be at least a default mode that just works out of the box. When they call your plugin something should happen, if you don’t at least have this, chances are people will pass on your plugin and keep looking for others. This makes it really easy for the developers and now allows them to tweak options as necessary.

Provide Plugin Options - This follows from the point above, once your plugin is working any modifications to it should be provided through some options. Don’t ask developers to have to create some kind of structure with div’s. Although this rule case can be broken as in the case of a jQuery slideshow plugin where a user may want to specify multiple images, for the most part, keep this in code and set it as an option to toggle on or off.

Thoroughly Test Your Code in All Browsers - This step is easy to do and only takes a little extra time and effort. This is also probably the most important step which will make or break your plugin. In many cases a developer may not find a bug in your code but a user most definitely will sooner or later. If users are reporting bugs and it turns out to continuously be your jQuery plugin, there is a good chance it will get dropped and replaced. Make sure you run a quick test in all browsers and sort out any last minor issues before release.

Document Your Plugin Code - Before releasing your plugin make sure you document it. Your code makes sense to you because you just wrote it, but it may not make sense to others or even to yourself three months ahead of time.