JS and CSS handlers in Clay

One of the things that have bugged me for a while is having Javascript files loading in the Clay themes, instead of per application. I had become accustomed to JS on-demand, thanks to Xaraya’s base-include and my xScript module for Xaraya. I decided to fix that this week.

I wrote 2 classes to handle JS and CSS, although they will likely be put somewhere else or even merged later on. In the process of creating the classes, I added a ‘common’ folder to the web root directory, which is for style sheets, JS, images, templates, etc that do not belong to a specific application (such as this case). I don’t have theme-specified overrides working for common yet, but that’s another story. Anyway, the JS and CSS handlers work the same as Xaraya or xScript, for the most part. They don’t have the more advanced features of xScript, but those will come. One of the things I’ve done a little differently is add a mode setting for how the JS and CSS is handled. If ‘external’ is selected, the files are linked within the page. If ‘internal’ is selected, the files are included and the code is placed within script or style tags. The later doesn’t look as pretty, as far as the HTML source goes, but the fewer HTTP Requests seem to make difference.

There are a few kinks to work out and some naming conventions to finalize, but overall the new handlers have made a big difference. I do have some features to add, but I’m not sure when they will fall in. To name a few: most of xScript’s features; code packing/minifying and caching; and the theme specific overrides. This was one of the few issues remaining that have been stalling the 0.5.0 release.

Tags: , , , ,

4 Responses to "JS and CSS handlers in Clay"

Leave a Comment