Don’t serve WAFileLibrary subclasses from Seaside

Most of us recognize that static files do not need to be served from Seaside, but it is a step that can be easily overlooked. I was recently helping someone analyze performance for a Seaside application and we found that serving the initial page made 20 Seaside requests, all but one of them for something in /files (i.e., a subclass of WAFileLibrary). In this case it was Scriptaculous, but it could be anything.

The first step to fix this is to find out which files are being served from Seaside. You can do this by looking at your web server logs or by looking at requests made by the browser (in Firefox, use Firebug). If you see SUDevelopmentLibrary being requested, then look for references to that class. Typically the class will be the argument to an #’addLibrary:’ message following a #’register:asApplicationAt:’ message. Remove the #’addLibrary:’ call and re-register your application.

Second, create operating system files containing the material previously served by Seaside. You can copy the text from the methods or you can obtain the files elsewhere. For example, to replace SUDevelopmentLibrary, go to the Scriptaculous downloads page. Note, however, that SUDevelopmentLibrary has an additional method, #’treePatchJs’, that is not included in the download. Typically these files would be placed in your web server’s /scripts directory.

Finally, add references to the static file(s) to your component. Typically this is done in #’updateRoot:’ on your component. For example:

Another approach is to Apache with mod_rewrite and the “-f” option. So during development you simply serve all files directly from the image. On deployment you simply write all the files of all libs (you use) to a directory served by mod_rewrite. You can even configure your deployment-image to do so on each start-up. Advantage is that development and deployment “files” are always in sync. By using the -f option nobody gets hurt if you forget to write them to a dir … and because mod_rewrite (or something similar for other servers) is used anyway it doesn’t even hurt in terms of running components or configuration.