Welcome Guest, Not a member yet? Register   Sign In
Partial Views -- How many is too many?
#1

[eluser]Unknown[/eluser]
I'm currently working on a project with a large number of fairly complex views. (Here I mean complex in reference to the XHTML and associated CSS.) The XHTML of these views may change significantly in the future.

I'd like to use CIs ability to load views within views to allow me to build small XHTML 'widgets' that can be used through the site. These widgets could be anything from simple rounded boxes to something more complex like a reusable comment form. This way, when the XHTML of a widget requires modifications the designers would only need the change the markup in one location.

Based on my initial research, each page would have anywhere from 10 to upwards of 100+ of these partial view widgets. Also, some of these widgets may themselves include partial views.

1) How 'expensive' (in terms of cpu/memory) is the loading of a partial view? Does my widget idea seem like a reasonable approach for what is expected to be a high-traffic site?

2) Does anyone have any real-world experience with a CI app that relies heavily on partials?

3) Any suggestion for a better way to handle this? One idea I've been considering is describing each view in terms of both the widgets involved and the data expected from the controller (using something like YAML or XML) and then 'compiling' these descriptions down to static files. This would remove the need for partial views completely, but it feels like major overkill. Smile
#2

[eluser]dmorin[/eluser]
On the one hand your problem will be IO and seeking many files from the HD to include them. However this will decrease as linux (unless you're using windows...) caches the files in memory.

It probably depends on what you're including in these partial views. If you're just including an image tag or something like that in a partial, then just create one config file/library/helper with all of these little things defined. Then, just call that from the views. Just an idea.
#3

[eluser]onejaguar[/eluser]
I would go for whatever you think will work best for ease of programming and doing updates; for performance look at building a memory cache of rendered views using memcached (http://www.danga.com/memcached/) or a similar caching scheme. This is what I did for a site that had lots of little sub-controllers and views that could be called either by CI controllers or via AJAX requests. I'd have a hard time imagining why you'd do this for 100+ widgets on a single page unless there was a lot of repetition in which case there may be a better way of doing it; hard do know without more details of what you are doing.
#4

[eluser]Seppo[/eluser]
The first problem I see is that per each view, CodeIgniter performs an extract, so if you have many variables this may slow the things down... If you are using PHP5 I recommend to extend the Loader class and add a method to load a "mini-view" or widget with only the variable that widget needs, because CI always passes all variables to each loaded view.
#5

[eluser]Unknown[/eluser]
@dmorin:

I like your widget helper idea. I also didn't know that Linux cached files in memory. Thanks.

@onejaguar:

I'd definitely like to incorporate Memcache into this site. However, due to the dynamic nature of the page data, caching the rendered views may not be a big win.

@Seppo:

Thanks for the tip. After reading your post I dug into the CI source to see exactly what was going on inside the Loader class.


Looks like I'll be creating a widget-loading helper.




Theme © iAndrew 2016 - Forum software by © MyBB