cancel
Showing results for 
Search instead for 
Did you mean: 

Responding with a pre-processed webscript

jvanderhoef
Champ in-the-making
Champ in-the-making
My site currently depends on webscripts to build all its pages, what I'm trying to do is have each webscript save a static version of the page it generates into the alfresco respository, and successive requests for that webscript will respond with the static page it gernerated if it exists. This will save alot of processing time for my pages.

So far, I've only been able to have the webscript create a static file and populate it with the freemarker template, but don't know how to have it respond with the static file if it exists, also having issues with passing the freemarker template arguments.

Here is part of my code.


model.folders = getData(requestedFolder);

var htmlCheck = companyhome.childByNamePath("List.html");

if (htmlCheck != null)
   {
//need to return static page if it exists
   }
   else //process the webscript
   {
var template = companyhome.childByNamePath("Data Dictionary/Web Scripts/Testlist.get.html.ftl");
var document = companyhome.createFile("List.html");
var StaticResult = document.processTemplate(template, model.folders);
document.content = StaticResult;

}

I've been trying to get this to work for awhile, was wondering if anyone might have some ideas. Currently just trying to prove the proof of concept. Thanks
3 REPLIES 3

rogier_oudshoor
Champ in-the-making
Champ in-the-making
I'm trying to think along here, so please bear with me Smiley Wink

You want the total response from your webscript (which is javascript + FTL) to be cached right? You would probably be easier off by using a Java filter (which would simply block the request going into alfresco), which would be massively faster but not so easy to access the repository because you'd have to use the Java API. Another advantage is that your webscripts are much simpler, as they are cached by an external entity.

Alternatively, you'd need to have an FTL template looking like
${entire-page!""}

where in javascript you use
model.entire-page = htmlCheck.content;

zaizi
Champ in-the-making
Champ in-the-making
You know you can cache webscript responses. See http://wiki.alfresco.com/wiki/Web_Scripts#Caching. Use Squid as a reverse proxy to cache your web script responses. See http://www.visolve.com/squid/whitepapers/reverseproxy.php.

jvanderhoef
Champ in-the-making
Champ in-the-making
Using the built in caching method with webscripts is not really an optimal solution for me since it uses HTTP caching, I need server side caching to happen, still considering using OScache, but that is another discussion. The Java filter sounds like a winner but I'm not a developer per say, more of a front-end guy, but I'll pass that idea along to my developer friend and see what he thinks.

I'll explain the process I'm exploring a bit more:

I have 30-40 webscripts that generate pages and content.

When a user hits a page on the site the  webscript is fired and returns the page to the user, some of these take awhile to load due to the mass amount of information it is looking through.

What I'm trying to do is to see if when a webscript is called, it can be "baked" as a static page in alfresco, and any successive requests for that webscript will return the "baked" version. This would improve performance for anyone who requests that page, and the entire site would end up being faster as all the webscripts get "baked". Then if I update content within alfresco I can just go delete the "baked" page and it would get regenerated.

Thanks for your input, I know there are many ways to improvement of the performance of the site using alfresco, just exploring this one at the moment.