When you first visit my app on the web, or open it in cordova on device, there is some lag the first time you visit each tab before the view is cached. I was wondering if there is any way to cache all of these first, then let the user in.
Thanks!
When you first visit my app on the web, or open it in cordova on device, there is some lag the first time you visit each tab before the view is cached. I was wondering if there is any way to cache all of these first, then let the user in.
Thanks!
Ionic views are cached by default so are you sure that lag is caused by views and not by fetching data or something else?
Maybe Iām confusing caching the view with initializing the scope for the controller? if you visit this link http://gaindeck.herokuapp.com/ on mobile(this is less noticeable on a pc or in cordova, but still there), and click the last tab (timer) after opening, you will see the start button flash, but if you leave and re-visit the tab, it doesnāt flash. This is something very subtle but I think ironing it out would give a far less ājankyā first impression.
I should add: The app doesnāt fetch any external data and that buttonās presence is driven by an ng-if statement. Even if i did fetch cloud data in some controllers, could i do it before opening the tab?
I believe thatās only half true - read this thread for more information.
As you can see, view caching in Ionic only applies to views youāve visited - itās not a āpre-cacheā solution.
To use pre-caching, you can use a solution like Angular Template Cache, as explained in the thread.
Coincidentally Iāve just completed my new Ionic Starter App which includes an optimized gulp.js file that supports Angular Template Cache:
You can use this gulp file (or a variant of it) to perform a production build that includes template caching.
(blogged about it here)
Thanks a lot Loeb, this is exactly what Iām looking for. Though I am having some trouble getting it working.
My folder structure:
www/
tab-calendar.html (etc. html here and in some subfolders)
-----/js/
---------template.js
and Iām generating $templateCache.put(ātab-calendar.htmlā,
This seems right but it isnāt working, this block in your gulp confuses me
.pipe(templateCache({
standalone: true,
root: ājsā
}))
My gulp:
var paths = {
sass: [ā./scss//*.scssā],
templates: [ā./www//*.htmlā],
dist: [ā./wwwā]
};
gulp.task(ātemplatesā, function() {
gulp.src(paths.templates)
.pipe(templateCache({
standalone: true
}))
.pipe(gulp.dest(paths.dist + ā/jsā));
});
Anyway thanks in advance Iāll keep wrestling w/ it.
@jbalchun Well I think I know the reason why ā¦
Your templates are right under the root www directory (and subdirectories of it), while my templates are under ājsā (together with my Javascript files - I keep everything together).
This is the reason why I have āroot: ājsāā in my gulp file.
I think that in your case you need to put āroot: āāā (empty) then.
Tip: you can check this theory as follows by running your app in a browser (āionic serveā) after the gulp build.
Do the gulp build, then do āionic serveā and in your browser (Chrome or Safari or whatever) open the Developer Tools.
(so that would be the Chrome developer tools or the Safari developer tools etc)
In the developer tools open the Network tab and reload your app.
You will then probably see HTTP 404 for the templates that canāt be loaded.
Look at the path for the ā404ā files and you will probably see whatās wrong in the path and what you need to fix in the gulp task.
I had this too and in my case the problem was that it had āroot: ātemplatesāā instead of āroot: ājsāā which it had to be in my case.