HTML Include Tool (portal_html_includes)
This will be a tool for centralized management of javascript and css files. Currently, javascript and css files are included by ERP5 in two ways:
- hardcoded in global_definitions
added by fields which define Widget.get_javascript_list or Widget.get_css_list methods (e.g. PlanningBox)
The tool should:
- allow adding custom includes easily without having to overwrite anything, both manually and through business templates engine
- manage global (default) includes as well as those added by fields
- support caching and merging includes to reduce traffic and save on server resources
API
Currently the API is:
registerFile add a file to the set, per request
a.k.a. register and append - which is best?
extend add a number of files (a list of names)
registerCode add a raw code (js or css)
getIncludeCode get a cooked code to be inserted directly into a page's html - returns something like:
<script src=".../erp5/erp5.js"></script> <script> (some Javascript code) </script> <link type="text/css" rel="stylesheet" href=".../erp5/erp5.css"/> <style> (some css code) </style>
Usage
requires erp5_xhtml_style_experimental which contains modified versions of global_definitions and some other page templates
in /erp5/manage_main add "Experimental Tool" -> Javascript Tool
- in Properties tab type in extra javascripts
in /erp5/manage_main add "Experimental Tool" -> CSS Tool
- in Properties tab type in extra stylesheets
These will be always added; apart from that, evey script or ZPT can add its own css/javascript files or code; this is handled per request.
These tools go together with ZPTs from erp5_xhtml_style_experimental. The default js and css are still defined in global_definitions, though they are now handled by portal_css and portal_javascript.
Next steps
Decide on final API
Define in business templates
The best (I think) way to handle core and extra css and js is to include the files in portal_skins per bt5, and define in bt5 properties which files should be added to the default file set (in a similar fashion to skin layers).
Cache and merge
The tool will have a merging and caching mechanism; the idea is to do it as follows:
- when asked to cook a code first calculate a hash of all file names which should be used in the cooked code
- concatenate all these files and cache using the hash as key (or skip if the key is already there)
- return a tag referring to the tool with the hash in the url
- when called with a hash, return the concatenated code from cache