update: terribly sorry for not making myself clear. it is load() in jQuery, not loadpage().
maybe this is a trivial question but I just cannot think it through as new to js. I will really appreciate your help.
I am building a small personal site, containing several similar pages. Some tutorials I find suggest to use load() to, in one single .html file, based on different clicks, generate different content which is grabbed from my other html files using load().
but why am I doing this? having several html files works fine. using load() method I still need those files; also I googled and see many complaints about the slow speed of load().
therefore I am just wondering the reason we are doing this.
Thank you in advance.
loadpage()is not a native jQuery method, so it’s likely you’ve stumbled across an article that was providing some custom wrappers for jQuery’s methods. On the other hand,$.load()is a native jQuery method that pulls remote content into your page asynchronously. Changes are good that if somebody constructed aloadpage()method, they may have in fact been using$.load()(or any one of the other ajax methods) internally.It’s possible you’re referring to
$.mobile.loadPage(which uses jQuery’s$.ajaxbeneath the covers), which is actually a jQuery Mobile method. You wouldn’t be dealing with this too much unless you’re involed in Mobile app development.Whether you’re using jQuery Mobile’s
$.mobile.loadPage, or jQuery’s$.loadto load in your content, the reason is still the same: avoid full page refreshes when partial page loading is all that’s needed.Think about what happens everytime you want to load a different HTML file. You have to reload the header, the navigation, the footer, sidebar information, graphics, and perhaps some media content, every time you load a new page – and a lot of this doesn’t change from page to page. This is why it’s helpful to be able to load in fragments of documents, without requiring the user to re-issue a request for everything all over again just to see the unique content on page 2.