Page 1 of 1
css minified?
Posted: Wed Sep 05, 2018 1:01 am
by magallo
Hi all, does anyone knows how to minify the default {cms_stylesheet} ?
is it possible to minify the css files?
thanks
Re: css minified?
Posted: Wed Sep 05, 2018 2:28 am
by DIGI3
There's no plugin for that currently, but enough people have asked for it that I'm sure someone would write one if a few people could sponsor it.
You can always just use [[strip]] in your stylesheet templates and be most of the way there, and if you're using compression on your server, then minifying won't really accomplish anything anyway - other than silencing SEO experts.
Re: css minified?
Posted: Wed Sep 05, 2018 3:13 am
by magallo
Thanks for the feedback, in fact I do need to silence the seo experts
I'm going to give it a try. I'm also going to try using the [[jsmin]] tag. Lets see if it helps.
Re: css minified?
Posted: Wed Sep 05, 2018 7:06 pm
by magallo
I created a plugin that would minify the existing default {cms_stylesheet} here:
http://dev.cmsmadesimple.org/projects/cssminifier
to use it, you need to add the following into the template:
Code: Select all
{capture assign=stylesheets}{cms_stylesheet nolinks=true}{/capture}
{cssMinifier css=$stylesheets}
next version will take the data from the database.
Let me know your thoughts.
Re: css minified?
Posted: Thu Sep 06, 2018 2:36 pm
by deactivated010521
Ofcourse somebody will write a CSS optimization module when enhough funds are raised. But there are already tremendous JavaScript optimizers that are hard to beat and standardized on other open-source projects.
Implementing pre- and postprocessors is something you can start with today for example: Export your Design Manager CSS files and compress them with: cssnano + css-mqpacker
https://cssnano.co
https://github.com/hail2u/node-css-mqpacker
Btw: When you bump the exiration dates on the default cmsms/doc/htaccess.txt file (access plus 1 year) most speed test tools also give a better score. SEO fanatics will love it.
Re: css minified?
Posted: Thu Sep 06, 2018 3:47 pm
by PinkElephant
Thank you!
magallo wrote:Code: Select all
{capture assign=stylesheets}{cms_stylesheet nolinks=true}{/capture}
{cssMinifier css=$stylesheets}
I was lazy and went with
Code: Select all
{cssMinifier css={cms_stylesheet nolinks=true}}
... and it seems to work well.
(It looks like the hardcoded 'tmp/cache' will miss when $config['tmp_cache_location'] is set).
Why this matters to SEO is beyond me.
EDIT: Forgot to say it might be worth including additional
css units like rem.
Re: css minified?
Posted: Thu Sep 06, 2018 5:40 pm
by magallo
PinkElephant wrote:(It looks like the hardcoded 'tmp/cache' will miss when $config['tmp_cache_location'] is set).
You're making a good point, i was not aware of this $config option.
btw, i already have a working version that grabs the data directly from the database but it will only convert [[root_url]] to $config['root_url']. I think it's too complicated to convert all the smarty processing : [[$red = '#900' scope='global']].....
Re: css minified?
Posted: Fri Sep 07, 2018 6:32 am
by deactivated010521
Css Custom Properties catch up and will become a good replacement for variables set in Smarty in after ie11 is phased out:
https://caniuse.com/#feat=css-variables.
Maybe you can process (the uncompressed) CSS templates through Smarty first and put that into your minifyCSS function after.
https://www.smarty.net/docsv2/en/api.functions.tpl
-- untested --:
Code: Select all
$uncompressed = $smarty->fetch('uncompressed.css');
minifyCSS($smarty->display('eval:'.$uncompressed));
Re: css minified?
Posted: Sat Sep 08, 2018 2:27 pm
by velden
Note:
Without having a look at the code I think it's bad practice to read the data from the database directly.
Available API's should be used.
Re: css minified?
Posted: Thu Sep 13, 2018 1:39 pm
by deactivated010521
velden wrote:Without having a look at the code I think it's bad practice to read the data from the database directly.
What do you mean?
cssMinifier is reading a file from the tmp directory.
smarty methods are not protected and part of the cmsms api.
my example is pseudo code btw.
Re: css minified?
Posted: Thu Sep 13, 2018 1:49 pm
by velden
magallo wrote:
...
btw, i already have a working version that grabs the data directly from the database but it will only convert [[root_url]] to $config['root_url']. I think it's too complicated to convert all the smarty processing : [[$red = '#900' scope='global']].....