Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

HTML

Craig Jamieson
Craig Jamieson
19,585 Points

Loading pages in the background

Hi

I am not sure if I watched this technique here, but I have seen something that loads pages in the background, usually common pages people might go to next on your site. The code is applied to links. Can anyone tell me what this is or how to go about doing it?

Thanks in advance Craig

2 Answers

There are a few ways which you can do this. However, they all require a little more than HTML (unless you use iframes, which are considered deprecated).

You can use jQuery's .get()** or *javascript .post() functions to retrieve content, and then use the jQuery .html() function to update the content within the webpage. This way, the client does not need to update the page. Instead, just use the ```.click(function() { / callback */ })``` event handler to capture the event by "binding" it to a link, or even a span tag.

The AngularJS Team Treehouse Course

Here is some information on using the jQuery AJAX function (not using post or get, but specifying which).

Here is some information on how to use jQuery .get() or .post().

You can also use AngularJS which relies on jQuery to operate. By creating a controller in Angular, you can then specify the ng-view directive within an HTML element (like a div element). Using the angular-route.js file in the AngularJS package.

Here are some information on Angular's $route service if you would like to read more about it:.

Here is a simplistic way of using $route in a tutorial. Here is the precursor to day 2

Here is another tutorial showing how $route can be used.

Craig Jamieson
Craig Jamieson
19,585 Points

Thanks for replying to my post, but this is not the technique I'm talking about. It's a way of pre-fetching pages, and if I remember correctly it was something done directly in the HTML. I know their are some js scripts that could do this, but I was pleasantly surprised top discover that it's native to modern browsers and html5. I just can't remember where I discovered this and what to do.

There is link prefetching, http://davidwalsh.name/html5-prefetch

Craig Jamieson
Craig Jamieson
19,585 Points

I did think of link prefetching as you have shown, but I actually thought I'd seen something else. But I have literally gone through my history for the past month and found nothing.