Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate page prefetching in $routeProvider #206

Open
mlegenhausen opened this issue Jun 12, 2013 · 5 comments
Open

Integrate page prefetching in $routeProvider #206

mlegenhausen opened this issue Jun 12, 2013 · 5 comments
Labels

Comments

@mlegenhausen
Copy link

Problem:

  1. Keeping all pages in a single HTML document is not practical for bigger applications.
  2. Using $.mobile.page.prototype.options.domCache = true; results on heavy usage in the same result as 1.

Solution:
Use jqm page preloading.

Problem 2:
Does not work so well when using ng-click and changing the page via $location.path().

Solution 2:
Integrate the caching in the $routeProvider.

Example:

$routeProvider.when('/', {
   jqmOptions: {
      domCache: ['page1.html', 'page2.html']
   }
});

This should load the pages in the background after the route was changed successfully. This should also store the previous visited page so going back in the app is also as smooth as going forward.

What do you think?

@xliyong
Copy link

xliyong commented Jun 21, 2013

+1

@tbosch
Copy link
Contributor

tbosch commented Jun 27, 2013

Hi,
you can do the following: Create a route with a resolve property that calls $.mobile.loadPage, e.g.

                    resolve: {
                        prefetchPages: function() {
                            $.mobile.loadPage( 'page2.html', { role: 'page' ,prefetch: true } );
                            return true;
                        }
                    }

Start chrome and open the dev tools, the load this plunk: http://plnkr.co/edit/zxhGwCx1OSdi9ObTmfKC?p=preview
You should see that page2.html is loaded in the background while visiting the first page. And when you click on the link for page2 there should be no new network request.

Hope this helps,
Tobias

@xliyong
Copy link

xliyong commented Jun 27, 2013

Hi,

I have some directives that manipulate DOM and they needs to read width/height of DOM elements during initialization. Preloaded pages always return 0 for width / height, which makes the directives not functioning at all.

Do you have any idea how I can prefetch pages and at the same time re-initialize directives before showing the page ?

I have tried listening to JQM event and reinitializing directives on pageshow event, but I believe there are better ways to do it.

@mlegenhausen
Copy link
Author

The problem is the browser has never rendered the DOM element. You need to attach the elements to the DOM then they get a height. Maybe you can make a plnkr for this?

@sirair
Copy link

sirair commented Nov 16, 2013

I use the solution of TBosch for my prefetching. But I have the problem that I prefetch all the 10 pages in my app and when I navigate from page1 to page2 the page1 is removed from the dom. So when I go back to page1, it will be loaded again.
How can I reach that all pages exist in the dom for all time?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants