CMS Made Simple Forums
https://forum.cmsmadesimple.org/

css minified?
https://forum.cmsmadesimple.org/viewtopic.php?f=20&t=79009
Page 1 of 1

Author:  magallo [ Wed Sep 05, 2018 1:01 am ]
Post subject:  css minified?

Hi all, does anyone knows how to minify the default {cms_stylesheet} ?
is it possible to minify the css files?
thanks

Author:  DIGI3 [ Wed Sep 05, 2018 2:28 am ]
Post subject:  Re: css minified?

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.

Author:  magallo [ Wed Sep 05, 2018 3:13 am ]
Post subject:  Re: css minified?

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.

Author:  magallo [ Wed Sep 05, 2018 7:06 pm ]
Post subject:  Re: css minified?

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:
{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.

Author:  arnoud [ Thu Sep 06, 2018 2:36 pm ]
Post subject:  Re: css minified?

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.

Author:  PinkElephant [ Thu Sep 06, 2018 3:47 pm ]
Post subject:  Re: css minified?

magallo wrote:
http://dev.cmsmadesimple.org/projects/cssminifier
Thank you!

magallo wrote:
Code:
{capture assign=stylesheets}{cms_stylesheet nolinks=true}{/capture}
{cssMinifier css=$stylesheets}

I was lazy and went with
Code:
{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.

Author:  magallo [ Thu Sep 06, 2018 5:40 pm ]
Post subject:  Re: css minified?

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']].....

Author:  arnoud [ Fri Sep 07, 2018 6:32 am ]
Post subject:  Re: css minified?

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:
$uncompressed = $smarty->fetch('uncompressed.css');
minifyCSS($smarty->display('eval:'.$uncompressed));

Author:  velden [ Sat Sep 08, 2018 2:27 pm ]
Post subject:  Re: css minified?

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.

Author:  arnoud [ Thu Sep 13, 2018 1:39 pm ]
Post subject:  Re: css minified?

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.

Author:  velden [ Thu Sep 13, 2018 1:49 pm ]
Post subject:  Re: css minified?

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']].....

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/