0

I am following the official angular tutorial. I am at step 7 - routing and multiple views.

I've created a view for the list of items and another view for viewing a specific item. The list of items is loaded from server though a GET request.

From the list of items i click on a link that sends me to the specific item view, as it's done in the tutorial.

But when i hit the browser BACK button to get the item list view, the browser initiates another GET request to get the same list. Why is it doing that? Aren't views kept in the dom in a hidden state or as document fragments? It seems to me that angular completely deletes the view and when you later return to it - it recreates it completely. In backbone.js i've done a similar thing and when i navigate between views, the browser doesn't initiate new GET requests...

Can someone explain why angular makes this additional GET every time i navigate to a view that has not been modified in any way?

user2092119
  • 123
  • 1
  • 11
  • [this SO answer](http://stackoverflow.com/questions/20312226/angular-using-one-controller-for-many-coherent-views-across-multiple-http-requ/20312307#20312307) may help you – artur grzesiak Apr 27 '14 at 10:31

2 Answers2

1

AngularJS makes assumptions that the server has been configured properly. If you're serving static content that has appropriate expires headers, your browser should be returning a cached version of the view.

The upside to this is that you can return modified views to a user agent if you need to. It also facilitates HTML5 mode if you go that route.

Lucas Holt
  • 3,826
  • 1
  • 32
  • 41
0

By design angular routing destroys the old view and any controllers associated when navigating from view to view, it does not keep them hidden in the DOM, like JQuery mobile does, for instance.

In my case I had to pass the templates to the app through $templateCache initialization on page load.

You can read more here

Community
  • 1
  • 1
spacemigas
  • 791
  • 8
  • 10