user1650061
user1650061

Reputation: 75

AngularJS with ui-router lost the concept of SPA?

My question is just conceptual.

When you use the ui-router (docs) in your application, then you have a system built of multiple views. Right?

I was thinking about that, because looking at the network log of Chrome, every change to another view, the client-side makes a request to server to get the HTML files.

Upvotes: 0

Views: 86

Answers (1)

christianalfoni
christianalfoni

Reputation: 1034

Well, the definition of SPA might vary, but basically it has nothing to do with making requests to a backend. It is a matter if the browser needs to do a full page reload to make that request.

Traditionally Fill out a form, submit it and the browser is redirected to a new url. A full page request

SPA The application makes an AJAX request in the background. On its response it changes the URL manually and then changes the state of the application. There is no full page request, just JavaScript running in the background

But you are right about suspecting something wrong when there are lots of HTTP requests for templates. You do not want your application to do all these requests to the server. To avoid that you actually have to precompile your templates using a tool like grunt or gulp. Example: grunt-angular-templates. This will insert the templates in your JavaScript code and Angular just grabs them from there, instead of making a backend request. During development though it is no problem.

With modern frameworks you need a tool to "compile" your project for production. You want to concatenate all JavaScript files into one file, bring in precompiled templates and uglify the code. This is not something frameworks give you, you have to set it up yourself using tools like grunt or gulp.

Hope this was of help :-)

Upvotes: 2

Related Questions