Widening your JavaScript Application

Developer at Quick Left
Mar. 5, 2013
Widening your JavaScript Application
Widening your JavaScript Application
Widening your JavaScript Application
Widening your JavaScript Application
Widening your JavaScript Application
Widening your JavaScript Application
Widening your JavaScript Application
Widening your JavaScript Application
Widening your JavaScript Application
Widening your JavaScript Application
Widening your JavaScript Application
Widening your JavaScript Application
Widening your JavaScript Application
Widening your JavaScript Application
Widening your JavaScript Application
Widening your JavaScript Application
Widening your JavaScript Application
Widening your JavaScript Application
Widening your JavaScript Application
Widening your JavaScript Application
Widening your JavaScript Application
Widening your JavaScript Application
Widening your JavaScript Application
Widening your JavaScript Application
Widening your JavaScript Application
Widening your JavaScript Application
Widening your JavaScript Application
Widening your JavaScript Application
Widening your JavaScript Application
Widening your JavaScript Application
Widening your JavaScript Application
Widening your JavaScript Application
1 of 32

More Related Content

What's hot

AJAX & jQuery - City University WAD ModuleAJAX & jQuery - City University WAD Module
AJAX & jQuery - City University WAD ModuleCharlie Perrins
WordPress Rest APIWordPress Rest API
WordPress Rest APIBrian Layman
2.6 summary day-22.6 summary day-2
2.6 summary day-2futurespective
Denver AWS Users' Group Meeting - July 2018 SlidesDenver AWS Users' Group Meeting - July 2018 Slides
Denver AWS Users' Group Meeting - July 2018 SlidesDavid McDaniel
An admin's guide for getting work done with share point and powershell scriptingAn admin's guide for getting work done with share point and powershell scripting
An admin's guide for getting work done with share point and powershell scriptingInnoTech
5 Things You Shouldn't Do With A WordPress Plugin5 Things You Shouldn't Do With A WordPress Plugin
5 Things You Shouldn't Do With A WordPress PluginKelly Phillips

Similar to Widening your JavaScript Application

A Brief Intro to Adobe FlexA Brief Intro to Adobe Flex
A Brief Intro to Adobe FlexChad Udell
Get More Links to Your Site With the Skyscraper TechniqueGet More Links to Your Site With the Skyscraper Technique
Get More Links to Your Site With the Skyscraper TechniqueRachel Howe
Sanity on RailsSanity on Rails
Sanity on RailsMichael Kohl
Tìm hiểu Wordpress hookTìm hiểu Wordpress hook
Tìm hiểu Wordpress hookLương Bá Hợp
#ImpactSalesforceSaturday: Lightning Components 101: An Apex Developer’s Guide#ImpactSalesforceSaturday: Lightning Components 101: An Apex Developer’s Guide
#ImpactSalesforceSaturday: Lightning Components 101: An Apex Developer’s GuideNew Delhi Salesforce Developer Group
#BrightonSEO: Work Life Hacks - Tools & Tips to Improve Internal Productivity...#BrightonSEO: Work Life Hacks - Tools & Tips to Improve Internal Productivity...
#BrightonSEO: Work Life Hacks - Tools & Tips to Improve Internal Productivity...Alex Moss

Widening your JavaScript Application

Editor's Notes

  1. towards the end we’ll get into modern best practices
  2. Example simple landing page with a help modal might write some actual javascript which is often people’s first experience coding. exciting! a solid bet is to have a a main.js file with the docready, and a /libs folder with your libraries move right along to the next level of javascript apps when A) your docready call gets bigger than 50-100 lines, or B) when you start having several document ready calls. these might seem safe at first, but if they ever refer to the same
  3. just a few event bindings, maybe one of those newfangled AJAX calls, and some callback functions defined
  4. Example simple landing page with a help modal might write some actual javascript which is often people’s first experience coding. exciting! a solid bet is to have a a main.js file with the docready, and a /libs folder with your libraries move right along to the next level of javascript apps when A) your docready call gets bigger than 50-100 lines, or B) when you start having several document ready calls. these might seem safe at first, but if they ever refer to the same external variables or depend on one to be loaded first, you’re in for hurt. Race conditions!
  5. Small blog. Here’s an example:
  6. Global namespace for your app, a few nice buckets to store cached DOM nodes and data, and a simple init function to kick off some un-implemented functions. this is nice because a complex app only has one entry point, the doc ready call. new developers have it easy, and you can define well-named namespaces for further functionality
  7. So this can scale pretty well. You’ll start adding folders to organize your code, you might even dip into the waters of prototyped objects that you can instantiate many of. That’s very DRY (don’t repeat yourself)
  8. i’ll say it again, if you’re repeating yourself, you’re doing it wrong. prototypes can help you with that.
  9. you get there by consolidating down to one entry point, and make a properly organized namespace for your needs. this is also a time to factor out code you’ve implemented in several places maybe, like error popups after failed ajax calls. there are some other neat object-based ideas floating around like mapping the object to your routes, so when you visit users/index, it inits the app via App.Users.Index(), giving each page a unique entry point to control what happens on just that page. this is a solid way to organize code. I’ll make a totally uninformed guess and say that 75% of websites with javascript on them are set up in a way similar to this. It’s good and it works. Eventually though, you might find some pain points. You want to leave this level of application for any one of many reasons. sometimes you have classes that depend on other classes, and getting script tags to load in order is tough. Sometimes you might get tired of rebuilding the same functionality repeatedly and are ready to let a framework take on a more core role in your application. If you find yourself struggling to manage event binding and unbinding and keeping that in sync with the DOM, it might be time to progress. Another sure sign that your app might benefit from some more tooling is if you’re using javascript to produce lots of HTML.
  10. This is the final stage of organization and tooling for javascript applications. Think of the wildest, most complex things you’ve seen in a browser: analytics dashboards, gmail. This setup can tame all that complexity and make the project easy to work on and small to download. Let’s take these one at a time: Modules
  11. People wanted a format that was better than today's "write a bunch of script tags with implicit dependencies that you have to manually order", so... AMD
  12. Name the files this needs to run. Those correspond to the arguments passed into this function. Then: it’s just javascript. Return value is important.
  13. Model View controller. A model does... really good organization, easy to dive into a project. A lot of choices. I like Backbone. It is particularly easy to upgrade TO from more typical object focused javascript code. Backbone, for example, offers in piecemeal, a router, powerful collections with querying, models with great AJAX abstraction over them, and a handy view layer for gluing up templates and events to data from models. Pick any one piece if you like.
  14. Have you ever written code that looks like this? Raise your hand, it’s ok... I lied, it’s not ok. When you want to write HTML, you should be writing HTML.
  15. Aaah, HTML. Looks like HTML. With some data.
  16. Refactored, it looks like this. A function that returns HTML. Notice how you pass it an object to render against.
  17. Lot of choices, they all do the same thing. Some look like HAML, some have difference delimiters, some accept coffeescript <blech> but mostly it’s your preference They produce a function that when called, returns HTML. The file you write looks like HTML, but it’s output is a compressed, efficient mess of code that takes a while to produce.
  18. What do you do with your javascript before it goes to the browser? Uglify, minify, concatenate, resolve module dependencies, precompile templates, transpile coffeescript Grunt.js works well solo. Individual tasks or a whole process wired up Asset pipeline can handle it, Django has tooling for it, they’re out there.
  19. All at a once a big job, but these tools CAN be adopted piecemeal, though they all work fantastically well together. Level up? Move onto something wild like meteor.js... but seriously this is considered modern best practice for applications of a certain scale.
  20. move on when you want to do something cool when you start editing the libraries when you have too many doc readys that conflict when you can’t load things predictably and you can’t manage DOM complexity well