About jQuery Plugin Development In 30 Minutes

As an experienced jQuery plugin developer and the operator of a website devoted to jQuery education, I have had many opportunities to talk with other developers and understand what works and what doesn’t when it comes to learning how to build plugins. This short guide is intended to quickly get you up to speed with core concepts, which enable you to start building plugins of your own.

Experienced developers know that well-written jQuery plugins can reduce bugs, increase efficiency, improve collaboration, and save time. In jQuery Plugin Development in 30 Minutes (ISBN: 9781939924285), I’ll show you how to write clean and efficient jQuery plugins that are easy to maintain and collaborate on. While jQuery Plugin Development in 30 Minutes is intended for people who already have some experience with JavaScript and jQuery, most of the concepts in the guide will not require any advanced knowledge. Topics include:

Creating a plugin

Prototyping

Generate, Init, and Destroy

Handling events

Plugin options

Setters and Getters

Styling, CSS, and themes

Callbacks

Browser and mobile support

File organization and versioning

Boilerplate

I’ve also included bonus content, including sections on jQuery methods, utilities, selectors, and events, as well as a jQuery glossary. jQuery Plugin Development in 30 Minutes really is intended to be a short but productive read — my intention is to avoid the fluff and filler that make up 80% of most programming books, and just get straight to the point!

— Robert Duchnik

Learn more about Robert Duchnik, author of jQuery Plugin Development In 30 Minutes, on his author bio.

If you haven't started making your own plugins (and you should start) then this is a good guide to get you started down that road. You don't have to write plugins to share, you can also write them to clean up your own code.

Jeremy

Excerpt - Why jQuery Plugins?

Why should developers write plugins in the first place? I like to write as many plugins and libraries as I can. Reusability is key in reducing bugs and coding quickly. The more I use a piece of code, the more confident and familiar I become with it, which in turn significantly speeds up my development time.

When I write plugins, it may be for anything from larger-sized plugins for tooltips or select boxes to small jQuery extensions for removing a class by using a regular expression. When I solve a problem that might be reusable, I toss it right away into a utilities file (if it’s small enough) or build out a standalone plugin.

In my experience, requirements change quite often, or new situations will arise that weren’t anticipated at the start of the project. If the situation can be addressed with a plugin, I just whip open the standalone plugin page, make the updates and pop the new plugin back in. Because the plugin is self-contained, it’s easy to recreate the problem, fix it and get it back into the codebase. This is a far better approach than trying to find some random piece of code in the main codebase, and hoping that a change there won’t affect something else.

I write plugins using a standard format. It’s easy for me to go back months or even years later and understand exactly what is going on inside that plugin. It’s also easy for other developers to jump right in and make modifications. They can test it in the standalone environment, and, if it works, there is some confidence that it will also work once we insert the updated plugin into our main codebase again.

Ultimately, I try to think of my application’s main codebase as just stringing together various components and code from many sources. It just controls logic and flow. The real nitty-gritty is handled behind the scenes. This is why frameworks like Backbone are so important — they hide a lot of the details in the background and allow you to just focus on the flow and control of your application.

It’s also possible to open source our plugins on GitHub and similar sites. This can generate bug reports and contributions from the community while empowering other developers. In this sense, you will often be far better off investing your time searching for a plugin that is already available in the community and potentially updating that plugin rather than building out a completely new one of your own. A great place to look for plugins is the official jQuery plugins site. Sometimes, purchasing a plugin for a few dollars is the best bet. A purchased plugin will likely come with better support and be much more stable if there is money going into its development.

Finally, a good standalone plugin can also make you a fair amount of money. Many developers make a decent living by simply maintaining and updating one or two crucial plugins that are far better than anything available for free.

In the time we have left, we’ll cover the nuts and bolts of building a jQuery plugin. Let’s get started!