This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

Troiscent
Troiscent

Hello,

I noticed that the assets you add using

function onStart()
{
  $this->addCss('...');
  $this->addJs('...');
}

are not combined neither minified. Is there a way do it ?

Thanks

Alex

Troiscent
Troiscent

Hello,

Any tips or ideas about that ? I plan to build a modular way to present content (independant partials that contains needed CSS and JS files).

The problem is that if the website is a combination of independant partials, I will finish with a huge list of css and JS files which is not recommanded. So I would like to combine them all.

Thanks

Alex

daftspunky
daftspunky

This could be what you are looking for, for example:

    use System\Classes\CombineAssets;

    public function onRun()
    {
        $assets = [
            'assets/vendor/mustache/mustache.js',
            // ...
        ];

        $this->addJs(CombineAssets::combine($assets, $this->assetPath));
    }
Troiscent
Troiscent

Thank you for your answer

It cover a part of my question, your code seems to combine assets in one partial.

I would like to conbine assets between several partials.

For example I have that code :

<section class="blog">
  {% partial blog.htm %}
</section>
<section class="showcase">
  {% partial showcase.htm %}
</section>
<section class="contact">
  {% partial contact.htm %}
</section>

With the code you gave me, each partials have their css / js combined, so you have 3 combined assets for JS and 3 combined assets for CSS

I would like to have 1 combined assets for CSS and 1 combined assets for JS from the 3 partials.

Is it possible by default ? Or it require to develop a plugin to do that (if it's doable).

Thanks

Alex

Robin
Robin

Did you find a way to solve this?

I Tried:

<script type="text/javascript" src="{{ [
            'assets/libraries/js/jquery-3.1.1.min.js',
            {% script_combine %}        
        ]|theme }}"></script>

but twig cannot be parsed in between {{ [ ] }}

Last updated

Troiscent
Troiscent

Still no solution for this. I think we have to wait for an october cms update or external plugin to allow to combine and minify assets added in {% script %} tag :/

daftspunky
daftspunky

Partials occur too late in the request life cycle to combine or inject assets. Even using this may not work, but you can try it:

{% put styles %}
    <link href="{{ [
        'assets/less/theme.css',
        'assets/less/vendor.less',
    ]|theme }}" rel="stylesheet">
{% endput %}

1-7 of 7

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.