• How To?
  • Tips ‘n Tricks
  • WordPress
  • Snippets
  • Software
    • Browsers
    • Downloads
  • Web
  • Tools
    • Character Counter
    • chmod Calculator
    • Entities Encoder
    • Live HTML Editor
    • My IP
  • Contact
Twitter Facebook Google+ RSS
You are here: SumTips » How To? » Enable Prerendering on WordPress or any other Website

Enable Prerendering on WordPress or any other Website

Posted on August 4, 2011 by Renji | Short URL: http://sumtips.com/?p=4574

Google Chrome
Yesterday Google released the stable version of Chrome 13. This new version of Chrome browser has the interesting “Instant Pages” feature enabled by default. In case you didn’t know how Instant Pages work, Chrome pre-renders (preloads) certain pages in the background, like top search results or the ‘next page’ link in an article, which it thinks you will go to next. A pre-rendered page will appear to load instantly when clicked.

Here’s a video of the feature from Google:

You can now add support for this feature on your website and let Chrome, running on the visitor’s computer, know about any one link on your page that visitors are most likely to click next. It will then try to prefetch that page in the background and load instantly when the user clicks.

Enable Prerendering on a WordPress Website

Prerendering in Chrome is triggered by a <link> tag in HTML, similar to how prefetching is triggered in Firefox. So you can ask the browser to prerender a page on your website by inserting the link element with a rel of “prerender”.

Now there are two ways to add prerendering support on a WordPress website – by manually editing your theme template file or by adding a simple function to your theme’s function.php file. Choose the method you are comfortable with.

Template Method:

Open the header.php file in your theme folder and add the following code inside the <head>...</head> tags.
php if (is_archive()) { ?>


This code will work on WordPress pages for “category”, “tag” and “archive”, which normally spans to multiple pages. Chrome will automatically preload the next logical page, Ex. “Page 2″ if the user is on “Page 1″ in the background.

Function Method:
I consider this method as the easier and safest of the two. You can easily make changes to the code and it is preserved even after an automatic theme upgrade.

Open functions.php file found in your theme folder and add the following function anywhere before the last ?>.

function wp_prerender(){
	if (is_archive()){
		echo '<link rel="prerender"  href="' . get_next_posts_page_link() . '"/>';
	}
}
add_action('wp_head','wp_prerender');

And you are done!

Enable Prerendering on a Static Website

To trigger prerendering on a static website, add the following code to your html page:

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

Replace the page URL with the one you want.

Note: Prerending doesn’t work in Incognito mode in Chrome. More information about prerendering in Chrome can be found here.


Tweet

Related posts:

  • Web Page Prerendering – Super-fast Page Loads on Chrome
  • Enable Voice Search Feature on WordPress and Other Websites
  • How to Enable Multisite Feature in WordPress 3.1
  • Remove and Reorder Menu/Submenu Links in WordPress Dashboard
  • Customize WordPress Admin Bar by Adding/Removing Links
Categories: How To? | Tags: WordPress
Save Notes From Google+ to Evernote, Springpad and Remember the Milk
Customize New YouTube Black Video Player

One Response to “Enable Prerendering on WordPress or any other Website”

  1. Bernd says:
    September 9, 2011 at 9:31 PM

    It would be better to add additional validations to this code to avoid links to non existing pages (for example if the archive site is not paged in general or if the user views the last page. I published my solution here: http://goo.gl/Mea3F

  • Get Updates via Email

  • Recent Posts

    • CMS2CMS: Migrate Site from Drupal or Joomla to WordPress
    • WordPress: Add Preview Button in Distraction Free Writing
    • How to Activate or Deactivate Individual Jetpack Modules
    • Windows 8: Auto Update Defender with Windows Update Disabled
    • Automatically Start and Close Programs at Specific Time
    • How to Copy Code from Notepad++ with Syntax Highlighting
  • Random Posts

    • Know If Your Yahoo Messenger Buddy is Really Offline or Invisible?
    • Disable Office 2013 Splash Screens
    • Earn Points and Badges for Keeping Gmail Organized
    • Robocopy: Command-line Usage Examples and Switches
    • Safely Create Windows Hosts File with Hosts File Generator
    • Q&A Search Engine On SMS
  • Categories

    • Blogging
    • Games
    • Google
    • How To?
    • Linux
    • Microsoft
      • Windows
    • Miscellaneous
    • Phone
    • Snippets
      • AutoHotkey Snippets
      • CSS Snippets
      • htaccess Snippets
      • JavaScript Snippets
      • PowerShell Snippets
      • WordPress Snippets
    • Social
    • Software
      • Browsers
    • Tips 'n Tricks
    • Wallpapers
    • Web
© SumTips. Contact | Sitemap | Privacy Policy