Search code examples
google-chromegoogle-chrome-extensiongoogle-nativeclient

How to force Chrome to prerender more pages?


I'm learning about Chrome and Native Client.
Basically i want to increase number of pages that are prerendered
by chrome (now its just one page).

I was thinking about creating a extension that would
allow to prerender more pages.

Is this a way to go or am i left with hard coding it into Chrome and build from scratch?

EDIT
I started a bounty for this question. I would really appreciate some input.


Solution

  • No, there is no way to go, you would need to hardcode it in Chrome and rebuild as you noted.

    As you probably already know, Chrome explicitly states that they currently limit the number of pages that can be prerendered:

    Chrome will only prerender at max one URL per instance of Chrome (not one per tab). This limit may change in the future in some cases.

    There is nothing in their supported API's or their experimental API's that will give you access to modify this. There is not a toggle in chrome://settings/ or chrome://flags/ or anywhere else in Chrome currently that allows you to change this. You can however use the Page Visibility API to determine if a page is being prerendered.

    In addition to the one resource on the page that you specify using the <link rel="prerender" href="http://example.org/index.html"> you could also consider prefetching resources.

    The issue with prefetching is it will only load the top level resource of at the specified URL. So, if you tried to prefetch the other pages, like so:

    <link rel="prefetch" href="http://example.org/index.html">
    

    ...then only the index.html resource would be prefetched, not all of the CSS and JavaScript links containeed in the document. One approach could be to write out link tags for all of the contained resources in the page but that could get messy and difficult to maintain.

    Another approach would be to wait for the current page to finish loading, and then use JavaScript to create an iframe, that is hidden off the page, targeted at the URLs you want to prefetch all the assets for. The browser would then load all of the content of the URL and it would be in the user's cache when they go to visit the page.

    There is also a Chrome extension that combines these two approaches by searching for link tags that define a prefetch and then creates the hidden iframe causing the assets to be downloaded and cached.

    If the goal is to optimize around client performance for navigating your site there might be other alternatives like creating a web application that uses a Single Page Application (SPA) style of development to reduce the number of times JS and CSS are loaded and executed. If you are a fan of Google then you might check out their framework for building SPAs called AngularJs.