-
☆ A M B ☆
- 24,524 Posts
You might want to look at this
http://www.sepiariver.ca/blog/modx-web/manage-your-css-in-modx-with-csssweet
It uses a chunk for the CSS, and writes it to a minified .css file.
The automatic CSS and JS compression that you linked to in the rtfm is for the manager, not for the front-end.
-
☆ A M B ☆
- 24,524 Posts
I've modified this workflow somewhat, using resources in a separate context for my CSS blocks, and a pdoResources (or getResources) snippet in the cssSweet chunk.
[[pdoResources? &includeContent=`1` &context=`stylesheet` &parents=`0` &tpl=`cssChunkTpl`]]
My cssChunkTpl is just a very simple
The resources in the "stylesheet" context each contain blocks of CSS, such as for the main menu, the footer, and other discrete sections of CSS. It's also good for having one huge directive in one place, like an element with rounded corners, box shadows and a background gradient.
The cssSweet plugin now parses the chunk, minifies the parsed chunk's content, and writes it to my .css file.
I also suggested an improvement to the minification that cssSweet does
https://github.com/sepiariver/cssSweet/issues/2
Thanks for the tip! I've tested it briefly.
I find it a bit inconvenient when you have to clear site cache everytime you want to update css-file? Slows down development process.
-
☆ A M B ☆
- 24,524 Posts
It doesn't matter; the getResources call will gather up all of the resources' content.
The advantage to having something somewhere write to a file is that it's a lot faster for the web server to simply go find and serve a .css file, while if it's a resource it has to not find a file, realize from the .htaccess rules that it needs to load the index.php into the php interpreter, MODX gets run, figures out which resource to get, determines whether or not the resource is cached, returns the final page to the web server, which now (finally!) sends it back to your browser.
Here's exactly what I did:
1. Create a context "stylesheet".
2. Create resources for your CSS directives - make sure they're published, or else configure getResources to fetch unpublished resources.
3. Create the tpl chunk for getResources, with the [[+content]] placeholder in it.
4. Put the getResources snippet in the cssSweet chunk.
5. Check the plugin's properties to turn on the minification.
6. In my template, set the css link tag to the .css file that cssSweet writes to (by default, assets/components/csssweet/css-custom.css).
The SmartOptimizer extra is worth a look, makes it very easy to combine and minify. TBH this should really be done locally as part of your sass workflow.
-
☆ A M B ☆
- 24,524 Posts
My sentiments exactly. Getting all the SCSS/Compass/Grunt and what-have-you installed is a pain, not to mention learning how to use all that stuff.
I don't have a problem with one or two extra mouse clicks after I've done some work on the CSS resources. However, the plugin works on the site-refresh event. I would think you could change that to work on a doc save event instead, checking to make sure it's a doc in your stylesheet context before going into action. Could even use the plugin's properties to set the context. Or use a unique template for these resources, and use the template ID - this doesn't have to be done in a context.
I also make a few context settings to simplify things, like disabling the RTE and having search disabled and published enabled by default. And getResources can be configured to skip "category" resources if you want to use the tree structure to further organize the CSS blocks.