Forum Moderators: coopster

Message Too Old, No Replies

Caching rendered pages?

javascript problem

         

activeco

11:47 am on Jun 3, 2006 (gmt 0)

10+ Year Member



I want to cache rendered pages on my server, but the main problem is third party javascript code (the goal is providing the cache to browsers with javascript disabled).

HTML caching is not the problem, but embedded html into javascript makes me waisting time.
I would prefer PHP, but any other solution is welcome.

ifunk

1:09 am on Jun 4, 2006 (gmt 0)



People with JavaScript disabled should be shot :)

siMKin

2:37 am on Jun 5, 2006 (gmt 0)

10+ Year Member



can you give an example of a piece of javascript that you would want to cache in this way?

i don't see how you could cache generated html from a piece of javascript and still needing the javascript to do this for you in the first place.

vincevincevince

2:45 am on Jun 5, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I imagine you need to run a browser server-side - try Konqueror or Firefox running with Xvfb - and then grab the page contents using DOM traversal after the javascript has had a chance to load.

activeco

10:55 am on Jun 5, 2006 (gmt 0)

10+ Year Member



siMKin, the javascript produces just additional snippet of HTML code and nothing else.

vincevincevince:
Yes, a simple shell based browser (no X) with JS support for fetching and saving pages would be ideal.

I couldn't find anything about -Xvfb options you reffered to in neither Firefox nor Konqueror.
When I try it, I got a new window open.
Could you provide more info?

siMKin

11:17 am on Jun 5, 2006 (gmt 0)

10+ Year Member



siMKin, the javascript produces just additional snippet of HTML code and nothing else.

I understand that. But what i don't understand is this: The fact that you want to cache it, would suggest that the output of the javascript is always the same (otherwise it would be meaningless to cache it). But if it's always the same, why not simply just write HTML code, instead of generating it with javascript?

activeco

11:40 am on Jun 5, 2006 (gmt 0)

10+ Year Member



But what i don't understand is this: The fact that you want to cache it, would suggest that the output of the javascript is always the same (otherwise it would be meaningless to cache it).

It depends on remote db which doesn't change so often, so I could cache it safely, even for a few days.


But if it's always the same, why not simply just write HTML code, instead of generating it with javascript?

It's not always the same and it is third party js, I can't rewrite the code.

vincevincevince

4:07 pm on Jun 5, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



activeco - Xvfb (google it) is basically a 'virtual' X server. You can run it in the background or spawn it on the fly. It's useful for when you run a server with no display hardware (i.e. most racked servers).

You need to open firefox or konqueror using the Xvfb server as the screen, then let it render the page and use the DOM to grab the whole page. There might be something easier than using the DOM but that's what I'd try first as the JS will be modifying the DOM - read the DOM after JS is rendered and get the final HTML version of the dynamic page.

Alternatively - if this JS is predictable but changes, can you not simulate reading it via Perl/PHP/ASP etc. and figure out the output? i.e. if it says document.write('123'); you can extract just '123'.

activeco

4:51 pm on Jun 5, 2006 (gmt 0)

10+ Year Member



activeco - Xvfb (google it) is basically a 'virtual' X server.

Oh, in that way. I was looking for some special ff options.

Yes, it seems that would be the most simple solution.

Alternatively - if this JS is predictable but changes, can you not simulate reading it via Perl/PHP/ASP etc. and figure out the output? i.e. if it says document.write('123'); you can extract just '123'.

The problem is that such a code is generated in second step, after first js execution.

But this goes in more clear direction.
Thanks everyone, especially vincevincevince for his/her time.