HTML loading in Angularjs

321 Views Asked by At

I would like to ask if I am doing something wrong in my angularjs application. My HTML code is requested dynamically, but if I understand correctly single page apps should be loaded fully only once and each view should not be requested multiple times. For example every time I visit page /example with given templateUrl the following html template is loaded. It works fine, but I am scared that provided templates should load only fist time since it is a single page app.

.when('/example1', {
        templateUrl: 'example1.html',
        controller: 'example1Ctrl',
        controllerAs: 'vm'
    })
.when('/example2', {
            templateUrl: 'example2.html',
            controller: 'example2Ctrl',
            controllerAs: 'vm'
        })

example1.html is loaded when I am on /example1 and when I switch to /example2 example2.html is loaded etc.

1

There are 1 best solutions below

0
alpa_chino On

You have nothing to worry about. Each html file requested in the routes is loaded on a per route basis and then discarded once you move to a new route. It honestly is nothing to worry about.

With that being said, if you still want your html files cached, you can use $templateCache to achieve that. Check out the Angular JS $templatecache docs for more info.