9

I've been studying the difference between single page apps and multi page apps, and I think I have good view how they differ. Single page app starts by loading a single html page, and then it does never again fully refresh the page or override the original, unless the application is otherwise refreshed (browser refresh etc.) For example, the angularJS seed project: angular-seed has an index.html file. This file is the single page, that the server would send to front-end, and after that, all the other (possible) pages will be send asynchronously under the hood by using AJAX. So if you create app just with the angularjs seed, it is always going to be just a SPA application, am I right?

How in practice would you then create a multipage application with angularjs? Wouldn't you need multiple angularJS applications then? Would you have to have a separate routing for each of those angularJS applications? And why would one want to make multipage application for angularJS? Because one could always use the first index.html just as a shell, without real content, and then have separate container-pages for different pages. Could it be said that angularJS multipage app would be an application, that would just contain many SPA angularJS applications? In SPA, can you use the browsers' back-button, in order to go back to last view?

BornToCode
  • 9,495
  • 9
  • 66
  • 83
Ville Miekk-oja
  • 18,749
  • 32
  • 70
  • 106

1 Answers1

2

Yes, you've got the idea of SPA and MPA right.

Angular.js enables you to create SPAs but does not force you. In an MPA, I would not speak of multiple Angular applications since you would have just spread Angular.js modules over multiple HTML pages. The page flow or routing logic would then be in Angular.js controllers, in plain hyperlinks or in the backend on the server.

There might be reasons to not put a whole application under Angular.js. Maybe the authentication part of a web application might be Held separately for some reasons...

In SPAs you definitely can use the browser's back button. You just have to implement that somehow. Twitter solves this Problem by coding the state of its web application into the URL - if you're using Twitter, you might have noticed the symbols (#!) in the address bar.

Oliver Marienfeld
  • 1,154
  • 9
  • 17
  • But don't you need ng-app in html in order for angularjs document to be compiled? So you could not have angular.js modules over other html pages, without those pages also including the ng-app module? And if they do include the ng-app module, then they are considered as a separate application? https://docs.angularjs.org/api/ng/directive/ngApp. Also I don't understand the routing part. Would there not be any normal angular routing then? – Ville Miekk-oja Apr 15 '15 at 10:00
  • 1
    Yes, you have to initialize Angular.js somehow per page - see also https://docs.angularjs.org/guide/bootstrap - but that alone does not make two applications. – Oliver Marienfeld Apr 15 '15 at 11:42
  • When you say "application" you are talking about Angular.js applications, right? In that case, you can share one Angular.js application on multiple pages (you would have to Transfer the data from one page to another somehow...). Also, you could have multiple Angular.js applications on one single page. Or you could have a web application consisting of one page with an Angular.js application and another plain HTML page... – Oliver Marienfeld Apr 15 '15 at 11:51
  • Routing: On a SPA, Angular.js can take care of it by displaying different HTML fragments ("templates"). On a classical MPA web application you decide on the server side which page to display next. – Oliver Marienfeld Apr 15 '15 at 11:52