background preloader

Emberjs and Requirejs

Facebook Twitter

Bundling and minifying modular JavaScript (RequireJS / AMD) with ASP.NET MVC. Build a simple client-side MVC app with RequireJS. As a web developer, you certainly often started coding your JavaScript in a single file, and, as the code base gets larger and larger, it became really difficult to maintain.

Build a simple client-side MVC app with RequireJS

To solve this problem you can split your code in several files, add more script tags and use global variables to reach functions declared in other files. But this pollutes the global namespace and for each file an additional HTTP request consumes bandwidth, which slows down the loading time of the page. If this happened to you, you certainly understand that there is a strong need to organize our front-end code differently, particularly if we have to build large-scale web apps with thousands of lines of JavaScript. We need a new way to organize all this mess to make it easier to maintain. This new technique consists in using script loaders. In this step by step tutorial you will learn how to build a simple MVC (Model – View – Controller) app using RequireJS. Introduction. How to Structure Your Application Using RequireJS?

I've been using RequireJS, a module loading library for JavaScript, for the past few months.

How to Structure Your Application Using RequireJS?

Since I started I've learned quite a bit about it. It was a bit rough at first but forms a solid part of my toolkit now. I really find it hard to imagine JS development without it. It's like driving a Porsche without proper wheels... Just as frustrating. :) Besides providing nifty module syntax it allows you to optimize your project easily. Even though the project documentation is quite vast, it's pretty easy for a beginner to get lost in the detail. Before getting into actual application structure I'm going to cover some core concepts briefly. Fundamentals of RequireJS You can probably live without RequireJS in case you application isn't that big (say ~500 lines of code).

It allows you to separate your source code semantically into modules. The next snippet contains a few examples of possible module definitions to give you a better idea of what I'm talking about: Project Structure Source Structure. Use require.js without grunt · Issue #1 · tzellman/ember-todos. RequireJS AGAIN · Issue #2194 · emberjs/ember.js. Added a "loader" method in Ember.Router to be used to load files async by guilhermeaiolfi · Pull Request #2215 · emberjs/ember.js. AMD is Not the Answer : Tom Dale. Every so often, we get requests to make Ember.js support AMD (asynchronous module definition).

AMD is Not the Answer : Tom Dale

Until today, I had yet to hear anyone articulate why the advantages outweighed the (in my opinion) many disadvantages. Then, James Burke wrote an article called Simplicity and JavaScript modules that has so far done the best job outlining why AMD is good. However, I disagree with many of the assumptions and find many of the arguments outright contradictory. So, while James is both smart and I’m sure good-looking (and I agree with his comments on CommonJS), here are the reasons I think he is wrong about AMD.

Build Tools Are Okay However, for those of us who came from Dojo, requiring a server tool or compile step to just develop in JS was a complication. I have a lot of respect for Alex but, if this is his current opinion, he’s wrong. Many HTTP Requests. Ninja Geddesign - AMD is the Answer. Eight Ember.js Gotchas With Workarounds - CodeBrief. Having used Ember.js for a few months now, I have compiled a list of gotchas that I have encountered.

Eight Ember.js Gotchas With Workarounds - CodeBrief

Many of these will change/be fixed as Ember matures, but until then I hope these will serve as pre-emptive time savers for other developers. 1. Computed Properties and .cacheable() This one has actually been fixed in the lastest build of Ember, but I'm putting it here since it is still present in the latest 0.9.5 release. Consider the following object: It turns out that if you try and bind to the tags property of the above object, you will encounter an infinite run loop. Even though the infinite loop issue has been fixed, making computed properties cacheable is generally a good idea and will be more the rule than the exception.

Requirejs - ember.js and require.js. Upgrading to RequireJS 2.0 · jrburke/requirejs Wiki. Why There has been a good deal real world usage of requirejs, and there were some features around configuration that have come up that would be nice to add.

Upgrading to RequireJS 2.0 · jrburke/requirejs Wiki

At the same time, there were some configuration options and internal features that have not held their weight, and it would be good to remove them. Support for the AMD APIs has not changed. If anything, I am hoping that the AMD loader implementers are starting to agree on higher level APIs, like common config. The changes were more around the configuration and internal operation of requirejs. However, since some configuration options have been removed, and some things about how modules are loaded and executed were changed, semantic versioning dictates that these changes warrant a 2.0 version. Primary Changes These are the primary changes: Delayed module evaluation In RequireJS 1.0, any built file with a bunch of define() calls in them will have all the modules executed once a top-level require call is hit.

Shim config It gets bad if order!