0

Does anyone knows how to load angularjs views on page load? This will improve speed and minimize network traffic. For example this:

<div ng-switch-when="home">
    <div ng-include="'views/home.html'"></div>
</div>

"home.html" to be included from cache and without request to server every time the view is changed. Thanks.

1
  • 1
    I think it's safer and angular way to set this with route. Commented Jan 12, 2014 at 18:43

1 Answer 1

2

You can include templates on a page with

<script type="text/ng-template" id="views/home.html">
    <yourtemplatehere/>
</scipt>

http://docs.angularjs.org/api/ng.directive:script

Sign up to request clarification or add additional context in comments.

2 Comments

Can I set src of the template in script tag? There is no description in the documentation.
@Ivica I don't know. You could always try it. An alternative is to run through an array of template-urls to pre-fetch them and store them in the template cache

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.