This is more a “Am I thinking correctly” than a question.
I have a controller, and a function which loads a header view, dynamic content view, and footer view.
Within my content view there is a link which on click utilizing jquery changes the content. It does this by loading (using .load() ) the exact same controller but passing a var $ajax=’yes’;
Using this my controller knows not to load the header/footer again, but rather to just load the content part.
This works perfectly.
I then stumbled upon jqueries ability to load a fragment. Am I correct to think that my way of doing things is better in terms of resource usage, because utilizing fragment loads, I would be loading the whole page, then displaying just the fragment.. I.E No saving.
Assuming that is correct, is there any way to achieve what i am trying to achieve efficiently which does not require:
if(!$ajax){load header/footer}
at the start of each and every ajax based controller function?
Codeigniter’s built in way to check if a request is from an AJAX source is
so you don’t need to be passing
$ajaxback to know that it’s ajax.I think it’s far more efficient to check against ajax in the server side than to use jquery’s
.load()with a selector because you’re still loading the whole header/footer in the request, jquery is just being smart about picking out the content you’re after. So in terms of performance you’re not seeing any improvement over static pages, other than no full page refresh.