Currently Design Kit's CSS additions are computed at each page view. Moreover if the number of CSS additions in designkit.tpl.php is big, you get a huge html head that makes code unreadable and most importantly can increase dramatically the page size.
It could be really useful to store all the CSS additions into a separate CSS stylesheet, which could be then aggregated with the other ones.
I managed to implement this solution in a project of mine with some custom code, I can provide a patch if this feature is deemed worth of interest.
Comments
Comment #1
archnode commentedI am interested! It would be great if you could provide some code / a patch.
Comment #2
plachSorry, but before working on a patch I'd like to hear a word by the module maintainer.
Comment #3
yhahn commentedI think this is a good idea but implementation will be tricky -- designkit can be used to generate very dynamic styles (e.g. styles may change from page to page) so the mechanism for rendering the styles to a file and caching it is not as simple as write and forget about it.
My suggestion for now is to keep your designkit CSS as slim as possible, using the normal CSS stack for as much as possible and implementing only dynamic styles using designkit.
Comment #4
plachMy problem is I have to make a site's base theme fully recolorable (about 20 colors and dozens of CSS rules). I have no way to make the CSS simpler. What about having an option that allows to choose if using a generated stylesheet or a dynamic one?
Comment #5
yhahn commentedI think this would be a reasonable approach that avoids a lot of the trouble with caching rules, etc.
Comment #6
plachAnd here is the patch: as discussed above, one can choose between dynamic styles in the HTML head and a linked (generated) stylesheet through an option in the theme settings.
Comment #7
wwhurley commentedYou're probably better off using CTools for this, since they already have most of this done. Below is a patch to enable this.
Index: designkit.module
===================================================================
--- designkit.module (revision 687)
+++ designkit.module (working copy)
@@ -53,8 +53,9 @@
// Add styles.
$styles = theme('designkit', $color, $image);
// Provide in separate variable for themes that reset or blow away styles.
- $vars['styles'] .= $styles;
- $vars['designkit'] = $styles;
+ ctools_include('css');
+ $filename = ctools_css_cache($styles, FALSE);
+ $vars['head'] .= '
'."\n";
}
}
Comment #8
wwhurley commentedProbably better to use the ctools_css_cache table as well. That way you don't go through the problem of MD5-ing the CSS every request. Attached is a patch that uses ctools_css_store and ctools_css_retrieve using a key built from the current theme as well as the space type and id if active. An alternate solution would be to get the URL from url() to include PURL and use that as the key, but that's going to seriously bloat your table.
Comment #9
plach@whurleyf1:
Sorry, but #8 does not work for me and does not implement what we agreed in #4 and #5. Here is an enhanced version of #6 that avoids the need of clearing caches after saving new colors with CSS preprocessing active.
About introducing a dependency on CTools for one line of code I'd like to hear yhahn's feedback.
Comment #10
plachThe patch :)
Comment #11
wwhurley commentedI'm a fan of CTools, personally, and it makes sense, IMHO, to let it handle the nitty-gritty of storing the files and maintaining the cache. But I think you definitely need to account for Spaces in function designkit_stylesheet_save() otherwise Designkit overrides for a Space aren't going to be evident.
Comment #12
nedjoStoring in a linked stylesheet would be a big performance gain for most sites.
There's probably a use case though for using both--some styles that are sitewide, others that vary by page. So rather than introducing a configuration option, we could have two supported stylesheets, one that is linked and one that is dynamically generated per page. If either is empty it would be skipped.
Comment #13
apmsooner commentedI ran the patch provided by Plach and it works great. I just wish there was a configuration option for color setting to use or not use so defaults can be setup but user has option to use them or not.
Comment #14
iaminawe commentedThis seems to be a big improvement to an already useful module - any chance that someone could make this patch D7 friendly - I tried to apply it against D7 module and it failed with the following errors
patching file designkit.admin.inc
Hunk #2 FAILED at 88.
Hunk #3 succeeded at 105 with fuzz 2 (offset -11 lines).
1 out of 3 hunks FAILED -- saving rejects to file designkit.admin.inc.rej
patching file designkit.module
Hunk #1 FAILED at 20.
1 out of 1 hunk FAILED -- saving rejects to file designkit.module.rej
Thanks in advance