It's pretty straightforward to open up the developer console and read the logs in Chrome (Ctrl + Alt + i or View -> Developer -> Developer Tools) and Firefox (Ctrl + Alt + i or Tools -> Web Developer -> Toggle Tools). It's somewhat less well known that there is also a similar set of developer tools available in Safari.
0 Comments
I was at the book store today, and a book caught my eye that was titled, "How Google Tests Software". To my delight, it was a book about unit testing. But it wasn't really a technical book about unit testing with any specific testing framework. It was more of a book about how Google is able to break down it's huge offering of services into small areas that over and over ship quality software fast. Page 6 of the book talks about the roles at Google; the different programming positions you could apply for if you wanted to work there. I thought this part was extremely interesting, and I couldn't help but visualize how I was doing all of these roles of my current job. It would be an interesting thought experiment to scale out the "TDD developer role" across a few people, and I really like the elegant way Google does it.
I was working on an Angular 1.4 project recently, and it was taking a crazy long time to load. It was a truly single page application (no routes) that ran as a web page inside of a corporate CMS program. Basically, a large corp would give it's employees Ipads, and all of the company apps would be "subapps" inside of the corporate container app.
How to Get an Embarrassingly Long Load Time
Sometimes you want to stretch out the development time of your project so you can get more money (just kidding! That's pretty messed up!). Really, I'm just showing you this because I made this mistake, and I don't want you to make it and wondering why your app is so slow to load. What I was doing was creating controllers and putting async calls directly in the controller's constructor, with no use of $timeout. In my situation the app was taking about 12 seconds to load! It would first be a white screen. Then it would show a weird half-finished version of how the DOM should look, and then finally my ready-to-use app would be displayed in all it's glory. For a web page, this is unacceptably long, and I now I know how prevent async calls from holding up the DOM rendering.
Those Dag Nabbit Asyncronous Calls
Asynchronous calls take time. That's the whole point of using them. You call out to something- a REST api, loading from the file system, and interval goes off... You really don't want your entire DOM rendering to be held up by an async event call, and really it never needs to be. It's easy to make rookie mistakes in Angular, though, and this is a pretty common one (luckily, there's an easy fix!). So, I just put a random async call in my controller, and now my DOM is all whacked out when it loads. What should I do?
$timeout to the Rescue!
Thanks to a post by a SO user, parliament, I discovered that if you use the $timeout service with no delay value then it just occurs immediately, but after the SOM has rendered! If you're curious, you can find the original SO question here: http://stackoverflow.com/questions/11125078/is-there-a-post- render-callback-for-angular-js-directive)
So, in the end here's how I changed my code. This is the old code, the terribly bad and slow-loading version:
angular .module('MyApp') .controller('SubheaderAppCtrl', function($timeout) { loadMasterJson(); function loadMasterJson() { // Code to do async calls goes here. And here's the speedy new hotness: angular .module('MyApp') .controller('SubheaderAppCtrl', function($timeout) { $timeout(function(){ loadMasterJson(); }); function loadMasterJson() { // Code to do async calls goes here. It's pretty amazing, but putting your async calls in this $timeout block will allow the page to finish rendering which makes it seem much snappier and prevents weird partial-renderings. It's important to note that this doesn't speed up the actual loading of the JSON files, and since it will take some time after the DOM renders you will probably want to put a loading spinner or some other loading indicator in the empty area that will display the data in the JSON files (if you have a visible area like that, of course). Don't Kick Yourself!
If you fell into this trap also, don't be ashamed. It's a little tricky, and wrapping your async calls in a $timeout with no delay does seem a bit hackish. The important thing is that know you know the right way to do it with the quickest load time; so don't forget it! :)
Yesterday, I was able to leave work early and make it to the AWS popup loft in Soho NYC before they closed. It's pretty awesome because it's 100% free. They have a ton of desks, chairs, free wifi, even snacks and coffee. It's just an open place in NYC where you can go, hang out, and work on stuff. I would go there a lot back when I was in between jobs, but this time I had different purpose- to talk to an AWS architect about NodeJS and Lambda.
I'm not gonna lie- this is a pretty noobish thing to do. I hadn't used AWS in a while, and I had forgotten that they only allow you to download the keyfile when creating the server instance. I had done this on the machine at my office, set up a bunch of stuff on the box, and left for the weekend. Then I allowed my home ip and tried to login, but I kept getting permission denied errors. Whoops! I was using the wrong keyfile. The problem then was that I didn't have the right keyfile!
|
AuthorThe posts on this site are written and maintained by Jim Lynch. About Jim...
Categories
All
Archives
March 2023
|