Welcome Guest, Not a member yet? Register   Sign In
How to cache only a part of a view (included views)?
#1

[eluser]term25[/eluser]
E.g. only the block or banners that are included into the main view like:

Code:
<div id="footer">&lt;?php $this->load->view('footer_view'); ?&gt;</div>

or

Code:
<div id="banner">&lt;?php $this->load->view('banner_view'); ?&gt;</div>

the problem is I do not have controller for them just views, because there is only a static content.

I was thinking that maybe if I make a new instance in footer_view, then I could use something like:

$this->output->cache(n); inside my view file

or is this approach completely wrong and I should do it differently?

What is the proper technique for caching blocks/modules on the page?
#2

[eluser]blekknajt[/eluser]
If those are just static files, I don't think it will make any sense to cache them.
#3

[eluser]term25[/eluser]
Big Grin good point. I guess you are right. However, what about flash? The same thing?

Is caching good just for database stuff and nothing else?

I mean, parts of code where you have some queries?

EDIT: I have a couple of php stuff there, but only something like &lt;?php echo date(Y); ?&gt; for copyright stuff etc.
#4

[eluser]obiron2[/eluser]
I know it's not the question you asked, but if you are always loading the same header and footer, have you thought about having a template file?

in your controller:

Code:
$data['main_content'] = 'the_bit_that_changes_view';
$this->load->view('template_view',$data);

In template_view;
Code:
$this->load->view('header');
$this->load->view($main_content);
$this->load->view('footer');

#5

[eluser]term25[/eluser]
[quote author="obiron2" date="1342704000"]I know it's not the question you asked, but if you are always loading the same header and footer, have you thought about having a template file?

in your controller:

Code:
$data['main_content'] = 'the_bit_that_changes_view';
$this->load->view('template_view',$data);

In template_view;
Code:
$this->load->view('header');
$this->load->view($main_content);
$this->load->view('footer');

[/quote]

Yeah, I know, that's what I am doing, I just simplified it a little bit.

I am just curious if e.g. 3 or 4 php functions are a reason to cache and make an html from it or not.
#6

[eluser]boltsabre[/eluser]
To the best of my knowledge, you cannot cache "part of a page" in the browser (if this is what you mean?).

You can cache the entire page, or nothing... that's it.

So you'd want to cache all your static pages, and those that are dynamic (lets say a blog page with commenting) perhaps refresh that page every hour or whatever suits your purposes best(on the form where users submit a comment, put a little message saying "Comments will be only be published after passing our manual review process" - you should have some kind of automatic "spam checking" at the very minimum, and this note will, hopefully, detract possible human (but not bot) spammers from even trying to spam your blog).

Then you have DB caches, but that's another story entirely.
#7

[eluser]CroNiX[/eluser]
He might mean cache as in render the partial view to a file, which is what I do, and not necessarily "browser cache". I have some UL trees with links that are fairly db/code intensive to generate, as they deal with a hierarchy of USA/State/Region/Area/City. I "pre render" those to the filesystem and then just include them when generating the final view. It sped up the process of generating a page by about 4x not having to generate those partials from scratch each time. Then on top of that, the final output uses CI's caching, but a modified version.

I just created a new folder in the views folder, and then include(APPPATH . 'views/folder/statename.php');




Theme © iAndrew 2016 - Forum software by © MyBB