Papa's Perspective

Easy Web Development with jsFiddle

jsFiddle is a free code-sharing tool that allows you to edit, share, execute and debug Web code within a browser.

Have you ever wanted to test out a new idea with some JavaScript and CSS quickly to see if you're on the right track? Have you ever wanted to share your source for HTML, JavaScript and CSS sample on the Web and allow people to run it? If so, you need to check out jsFiddle. Created by Piotr Zalewa, jsFiddle is a free code-sharing tool that allows you to edit, share, execute and debug Web code within a browser.

jsFiddle is a great tool for testing and sharing Web code. While you don't need to register for a free account, it's useful, since you can maintain a list of your projects, or "fiddles", on the dashboard. There are three main windows where you can type HTML (upper middle), JavaScript (lower middle) and CSS (upper right). Then you can run the code and view the results in a fourth window (lower right). Figure 1 shows the UI.

jsFiddle color-codes the syntax and offers a nice "tidy up" feature that reformats the code using appropriate indentation and spacing. You can also use the JSLint button to check your JavaScript syntax, which is a nice bonus.

When you edit a fiddle, you can create a new version of it by clicking the Update button. Or you can fork the code using the Fork button. The nice thing about the Update button is that it creates a new URL with a version number for the fiddle. This makes it easy to go back to previous versions of fiddles from the more recent ones, in case you need to refer back to previous code.


[Click on image for larger view.]
Figure 1. jsFiddle displays HTML, JavaScript and CSS in the same window.

You can check out jsFiddle by creating your own fiddle; you can also view someone else's public fiddle, such as the one in the previous figure that I created, which is located here. From here you can view, run or even fork the code to try your own variations.

One of my favorite uses for jsFiddle is sharing code snippets with colleagues when tossing around ideas. One way to do this is to share the public link. However, you can also share the fiddle on Twitter or Facebook using the Share button.

What I find most useful is the embed feature, which creates a link that will embed the fiddle in another Web page. This is ideal for embedding a fiddle's HTML, CSS, JavaScript and results in a blog page, for example. Below is my fiddle from Figure 1:

You can also automatically include specific versions of popular references, such as Mootools or jQuery, from the options window (on the left). Notice in Figure 1  that I reference jQuery 1.7.1. You can also choose to add your own references, such as Knockout, by providing an address from the Add Resources option. Simply enter the URL for the resource's source code and it will be available.

I'll leave you with three tips for using jsFiddle effectively. First, register an account and log in before creating your fiddles. This makes it easier to organize your fiddles under your dashboard. It also adds your jsFiddle username to the URL of your fiddles.

Second, remember to fill in the Info section for each of your fiddles. This allows you to give your fiddle a title and description, which becomes extremely useful when you start creating several fiddles and are trying to discern each fiddle's purpose.  Third, if you have no purpose for the intermediate fiddles as you go, click the Set Base button. This makes your current version of the fiddle the base fiddle, and all others will derive from it.

While jsFiddle is extremely useful, it's far from perfect. But I'm willing to live with its missing features and warts because its pros far outweigh its cons. jsFiddle isn't intended to be a full-fledged Web editor, but it is an excellent code testing and sharing tool that's simple to use and adds a lot of value. There are many other features that jsFiddle offers, and I highly recommend you check it out.

About the Author

John Papa is a Microsoft Regional Director and former Microsoft technical evangelist. Author of 100-plus articles and 10 books, he specializes in professional application development with Windows, HTML5, JavaScript, CSS, Silverlight, Windows Presentation Foundation, C#, .NET and SQL Server. Check out his online training with Pluralsight; find him at johnpapa.net and on Twitter at twitter.com/john_papa.

comments powered by Disqus

Featured

  • Compare New GitHub Copilot Free Plan for Visual Studio/VS Code to Paid Plans

    The free plan restricts the number of completions, chat requests and access to AI models, being suitable for occasional users and small projects.

  • Diving Deep into .NET MAUI

    Ever since someone figured out that fiddling bits results in source code, developers have sought one codebase for all types of apps on all platforms, with Microsoft's latest attempt to further that effort being .NET MAUI.

  • Copilot AI Boosts Abound in New VS Code v1.96

    Microsoft improved on its new "Copilot Edit" functionality in the latest release of Visual Studio Code, v1.96, its open-source based code editor that has become the most popular in the world according to many surveys.

  • AdaBoost Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the AdaBoost.R2 algorithm for regression problems (where the goal is to predict a single numeric value). The implementation follows the original source research paper closely, so you can use it as a guide for customization for specific scenarios.

  • Versioning and Documenting ASP.NET Core Services

    Building an API with ASP.NET Core is only half the job. If your API is going to live more than one release cycle, you're going to need to version it. If you have other people building clients for it, you're going to need to document it.

Subscribe on YouTube