Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialCraig Jamieson
19,585 PointsLoading 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
Sean Lum
11,949 PointsThere 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.
Sean Lum
11,949 PointsThere is link prefetching, http://davidwalsh.name/html5-prefetch
Sean Lum
11,949 PointsCraig Jamieson
19,585 PointsI 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.
Craig Jamieson
19,585 PointsCraig Jamieson
19,585 PointsThanks 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.