• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
most efficient way of loading views

#1
[eluser]brian88[/eluser]
Ive been loading view by using a template. But I wanna know which is the fastest way, not for me, but for users to download the page. So here I have 2 controllers and I wanna know whats the better way. Or if theres a better way other than these 2 options, give me some feedback( I dont want to use a big templating library, not a fan )

controller 1
Code:
// set SEO
$data['title'] = 'title';
$data['h1'] = 'h1 stuff';
$data['description'] = 'my description';

$data['info'] = 'more data...';

// get data
$data['nav'] = $this->main_mod->getNav();
$data['posts'] = $this->main_mod->getPosts();

// load views
$data['content'] = 'main/home';
$this->load->view('templates/main', $data);

In this one I pass data to views that don't even need it, which would slow down the page, correct?

or

controller 2
Code:
// set SEO
$seoData['title'] = 'title';
$seoData['h1'] = 'h1 stuff';
$seoData['description'] = 'my description';

$infoData['info'] = 'more data...';

// get data
$navData['nav'] = $this->main_mod->getNav();
$data['posts'] = $this->main_mod->getPosts();

// load views
$this->load->view('header_view.php', $seoData);
$this->load->view('info_view.php', $infoData);
$this->load->view('nav_view.php', $navData);
$this->load->view('home_view.php', $data);
$this->load->view('footer_view.php');

This one takes longer to do, but if the page loads faster for users then I dont mind doing it.

#2
[eluser]TWP Marketing[/eluser]
This is just an opinion.
I use something like your controller 1, passing superfluous data to some views which don't actually use it.
I agree that the technique in controller 2 results in faster rendering of pages. As a lazy coder, I don't always take the time to sort my data and pass only as much as needed for each view. Slap on the wrist for me...
Justification: The amount of date being passed is small, usually. The data array is passed by reference, hence the server isn't being beaten on as much as a full data copy would cause.
I look forward to hearing for others on this topic.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.