[z3] concatresource directive preview
Balazs Ree
ree at ree.hu
Mon Mar 20 15:25:54 CET 2006
Hi,
in the frame of the jsonserver product development I made a small zcml
directive called concatresource. It is a lightweight solution
for publishing a resource by concatenating more files and compressing
the result. It can be used like this:
<browser:concatresource
name="test.js"
files="test1.js
test2.js"
/>
It works with Five in Zope2.8 and in Zope3.2.
I decided to develop this because
- I wanted to learn how to do it
- I need to deploy it for jsonserver and AZAX
- I could not use Plone's ResourceRegistries because I want a
zope-only solution
- I could not use zc.resourcelibrary because it would require zope2.10
for the TAL namespace extensions - I need something that works in Z2 and
Z3, today
- (both products do more, this is simpler)
It can be previewed at
http://codespeak.net/svn/z3/jsonserver/branch/merge/concatresource
and can be used as a separate product on its own.
During this I had to deal with caching and the autorefresh of files. It
turned out that there is a trivial bug in Five, in the file resource.py
the line
header = request.environ.get('If-Modified-Since', None)
is actually wrong, it never gets the header. For Five it should be
header = request.get_header('If-Modified-Since')
for zope3 it should be (and it is correctly)
header = request.getHeader('If-Modified-Since', None)
But even that fixed it would not work. Since the problem that both Z3 and
Five have is that although they attempt to handle the expiration, the
modification date of a file is read only once from the disk, on startup.
So you need a restart to refresh the resources. In other words, refreshing
of resources is currently broken in both Five and Z3. I implement that
correctly in concatresources and my solution could be used in the
Five and zope3 base resource handling similarly. (I can volunteer to fix
that.)
The packer.py file that does the javascript and css packing is used with
kind permission of Florian Schulze but it's taken from Plone where it has
GPL, consequently we have a possible license issue that needs to be
solved... so take care please, at the moment it's just demo.
Any feedback is highly appreciated.
--
Balazs Ree
More information about the z3
mailing list