Re: speeding up heavy web apps with a php-js cache manager

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, 2011-11-13 at 18:39 +0100, rene7705 wrote:

> Hi.
> 
> I'm developing a CMS, with lots of javascript code.
> I haven't been satisfied with my page initialization speeds, so I've
> started on a caching system.
> 
> First, i used to call up javascript as needed, and just-in-time. But that,
> on a localhost setup, results in a second and a half delay.
> So now I include all javascript for the entire CMS as inline js in the
> <head> of index.php. Index.php gets gzipped of course.
> The difference is really noticeable, without looking at any counters even.
> 
> So far so good.
> 
> Now I'd like to implement a caching system for ajax requests.
> I was thinking to take URL, GET, and POST send parameters, and compare such
> a set to items in a local js cache.
> 
> If the local cache is not available, the ajax request is sent as normal,
> and the result is put in the cache.
> Javascript implementation could be as easy as changing
> jQuery.ajax(ajaxCommand) to cacheManager.ajax(ajaxCommand)
> 
> If the local cache is available, the onSuccess handler of the ajax request
> is called with the cached data.
> 
> On the server end, the cached items are put in a global JSON "FAT" file,
> again with URL, GET and POST as keys to a flat plaintext filename.
> 
> On the server, any "normal" ajaxable URL will call php code to update the
> server end cache.
> 
> Index.php would query the cache for a "subscription", a list of cache
> URL+GET+POST keys, and include these cached items as
> <div id="cache_idx" style="display:none"><!-- {"keys" :
> {URL+GET+POST+LAST_MODIFIED}, "data" : "cached-data"} --></div>
> From where the javascript cache manager would be able to find the data.
> 
> The javascript cache manager would include some kind of polling system, to
> get near realtime updates for it's cached data.
> 
> I'm convinced caching of ajax results would further increase my page
> initialization speeds.
> 
> I'm interested to learn about potential pitfalls, any opensource libraries
> that already do this, or any other tips you can think of.
> 
> Thanks for your time.


You shouldn't really cache POST requests. GET data is only ever meant to
fetch data from a server, which works well with caching, but POST is
meant to change the state of something on the server, so it may never
make sense to cache that, and could cause problems later on with things
being cached even if they appear as if they shouldn't.

If there are certain chunks of the content that will never change then
you could cache those I guess, although not sure how you would be able
to do that at the server level.

Another way to add some speed is to minify your Javascript, be it inline
or in a different file, which results in less bandwidth being used to
send the data, and less time to send it as it's smaller. Images can be
combined into a sprite map which can reduce the requests in the same way
you reduced them by making your Javascript inline.

If you use libraries like JQuery, use a public one such as that found on
Google Code. Many sites use it, so it is more likely a user has it
cached on their machine already from visiting another site that uses it.

These are all pretty basic techniques, and although they don't answer
your question exactly, they may be useful for you to achieve the same
goal.

-- 
Thanks,
Ash
http://www.ashleysheridan.co.uk



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux