
charlie at begeistert
Feb 9, 2009, 2:12 AM
Views: 640
Permalink
|
Hi, I've written a very simple view for concactenating resources such as CSS or Javascript files to reduce the number of http browser requests: from Products.CMFCore.utils import getToolByName from Products.CMFDefault.browser.utils import memoize, ViewBase class Javascript(ViewBase): """Return all Javascript from the skin as a single string""" folder_name = 'js' content_type = 'application/x-javascript' @memoize def contents(self): skin_tool = getToolByName(self.context, 'portal_skins') layer = skin_tool.getDefaultSkin() skin = skin_tool.getSkinByName(layer) folder = getattr(skin, self.folder_name) obs = [str(ob) for ob in folder.objectValues() if ob.meta_type == "Filesystem File"] return "\n".join(obs) def __call__(self): data = self.contents() self.request.response.setHeader("Content-Type", self.content_type) self.request.response.setHeader("Content-Length", len(data)) self.request.response.write(data) While this works fine, it seems to run considerably slower (about half the speed) than a PythonScript that calls the relevant objects explicitly via getattr(context, id). I'm a bit surprised at this but suspect it may down to whether the file system is actually accessed or whether a persistent object is being called. In my browser view it is impossible to avoid reading in the file again as this happens the __str__ method of the FSFile object. In the hope of enlightenment. Charlie -- Charlie Clark Helmholtzstr. 20 Düsseldorf D- 40215 Tel: +49-211-938-5360 GSM: +49-178-782-6226 _______________________________________________ Zope-CMF maillist - Zope-CMF[at]lists.zope.org http://mail.zope.org/mailman/listinfo/zope-cmf See https://bugs.launchpad.net/zope-cmf/ for bug reports and feature requests
|