7

I do not have access to java or node on my shared host. Is there a way to minify server side, so I can continue to use assetic, without these engines? Uglify uses node and yui-compressor (deprecated anyway) uses java.

Thanks!

3 Answers 3

16

There seem to be 2 filters using only PHP code:

You will need to install the minify php library through composer, and then use the cssmin and jsminplus assetic filters.

Sign up to request clarification or add additional context in comments.

1 Comment

I will give that a shot thanks! I don't know why I couldn't find that info on Google :-(
3

Just for clarify the steps:

  1. composer require mrclay/minify
  2. In symfony app/config/config.yml add to assetic config:

    # some stuff assetic: filters: # possible another filters minifycsscompressor: ~ jsminplus: ~

    1. In twig:

    {% stylesheets <your assets> filter='minifycsscompressor' %} <link rel="stylesheet" href="{{ asset_url }}"> {% endstylesheets %}

    {% javascripts <your assets> filter='jsminplus' %} <script src="{{ asset_url }}"></script> {% endjavascripts %}

2 Comments

I have tried this and when I do an assetic dump I get the following: Attempted to load class "JSMinPlus" from the global namespace. Did you forget a "use" statement? Minify is installed through composer fine (I can see the code in the vendor directory), do we need to register it in symfony in AppKernel.php (normally you use new to add a bundle) or something like that?
so after running into this issue myself, it appears that mrclay's github repo has a version 3 that appears to have namespaced the classes. You'll need to install one of the 2.x versions of the library and then it will work as expected. change your composer.json to be: "mrclay/minify": "^2.3"
1

I know this is an old topic, but I would like to add a small correction to @AdrianBrault's answer for anyone who stumbles onto this.

When installing the said minify library, you need to use the minifycsscompressor filter, which uses the MinifyCssCompressorFilter class. The cssmin uses a different minification library.

1 Comment

Thank, cssminify didn't worked, but minifycsscompressor did.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.