Welcome Guest, Not a member yet? Register   Sign In
Cache and time lag
#1

[eluser]JanDoToDo[/eluser]
Hey guys,

My client has a tree-view on his website however there is a lery large amount of data in the tree view and as such it is taking around 1-2 seconds to load on every page refresh. The treeview is loaded via a jquery load on document ready.

I cached the files using mp_cache and this helped by about 0.2s however it still takes a long time to load. Is there anyway to compress the output to reduce the size or do anything else with it?

I profiled the whole thing and its the echo start which returns output to the jquery ajax call which takes the time (presumably as it is being downloaded by the client)

I thought about :
1) gzipping it and so set the config to enable_compression but this doesnt work as the jquery output is called after data has been sent and so it doesnt compress and comes up with an error. Is there anyway to compress it otherwise?

2) multiple echo statements but figured this wouldnt help as its still the same amount of data.

3) The third thing i thought of was only loading sections when they are clicked on but this isnt optimal.

Does anyone have any suggestions?? Smile I think the most optimal would be if there is someway to compress the data, or alternatively store the tree client side instead of server side?
#2

[eluser]JanDoToDo[/eluser]
Anyone got any ideas?
#3

[eluser]richthegeek[/eluser]
The lag is from the server transfer and parsing by jQuery, not from the PHP.

Server transfers are never going to be as fast as you need them to be - the *fastest* I have ever seen is ~500ms and on average it's about double that. Regardless of how small the output is (500ms was with a <10 char string as the output) or what encoding you use, the transfer will always have a minimum required for DNS resolution, connection, acceptance of the response, and initial parsing by the javascript (pre-callback).

Long story short, you should be creating the tree structure on page output (ie, via PHP) and controlling just the collapsing/expanding with jQuery.
#4

[eluser]bretticus[/eluser]
Rich is right. The revolution of AJAX was that you could work on smaller subset of data to avoid stuff like parsing an entire tree view, etc.
#5

[eluser]JanDoToDo[/eluser]
So all in all I can't compress the output or cache it client side in some way...?
#6

[eluser]bretticus[/eluser]
[quote author="JanDoToDo" date="1265731642"]So all in all I can't compress the output or cache it client side in some way...?[/quote]

How much data are we talking about here (you say "...a very large amount..."?)

Apache can compress the output. PHP (maybe CI) can even do gzip compression. You can cache the file using a CI caching object. You can even store it in memcache or APC (or other op caching extensions.)

If those help, than do that. But the point we were trying to make is that you SHOULD NOT be storing large amounts of data client-side. Furthermore, with AJAX, you probably don't have to.

Is there any way you can get some and not all of the "tree view?" If so, all you have to do is send a query via AJAX that returns a portion of the data and then just populate that portion of the tree via javascript code (which will perform substantially better.)




Theme © iAndrew 2016 - Forum software by © MyBB