Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Backbone.js Patterns and Best Practices

You're reading from   Backbone.js Patterns and Best Practices Improve your Backbone.js skills with this step-by-step guide to patterns and best practice. It will help you reduce boilerplate in your code and provide plenty of open source plugin solutions to common problems along the way.

Arrow left icon
Product type Paperback
Published in Jan 2014
Publisher Packt
ISBN-13 9781783283576
Length 174 pages
Edition Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Swarnendu De Swarnendu De
Author Profile Icon Swarnendu De
Swarnendu De
Arrow right icon
View More author details
Toc

Table of Contents (19) Chapters Close

Backbone.js Patterns and Best Practices
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
1. Reducing Boilerplate with Plugin Development FREE CHAPTER 2. Working with Views 3. Working with Models 4. Working with Collections 5. Routing Best Practices and Subrouting 6. Working with Events, Sync, and Storage 7. Organizing Backbone Applications – Structure, Optimize, and Deploy 8. Unit Test, Stub, Spy, and Mock Your App Books, Tutorials, and References Precompiling Templates on the Server Side
Organizing Templates with AMD and Require.js Index

Precompiling with the requirejs-tpl plugin


With AMD, we simplified the template organization process, but the end result still remains an uncompiled template string. In Chapter 2, Working with Views, we saw how template compilation affects application performance every time and we also analyzed the benefits of precompiling templates. Won't it be useful if we have something that will load these template files and provide us with an already-compiled template string instead? Fortunately, there are multiple tpl plugins available for Require.js that automate template compilation, and you can use these plugins directly in your module definition. Let us look at a similar plugin (https://github.com/ZeeAgency/requirejs-tpl) developed by ZeeAgency. Dependency loading is exactly the same as it is for the text plugin, you just need to use the tpl! plugin prefix instead of text!:

 define(['tpl!your-template-path.tpl'], function (template) { 
  return template ({
    your: 'data'
  });
});

Now, r.js provides optimized and packaged precompiled templates. The tpl! plugin is surely more handy and useful than the text! plugin.

Template organization with Require.js is one of the best ways to maintain templates; a lot of JavaScript developers are opting for it nowadays. If you are using AMD for your Backbone application, go for it without any hesitation.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image