canton7 / fuelphp-casset

Better asset management library for fuelphp (with minification!)
MIT License
103 stars 29 forks source link

Assets are rendered several times #44

Open hammat opened 11 years ago

hammat commented 11 years ago

When using Casset in partials, it renders the same file several times. Then it causes conflicts for javascript.

Shouldn't Casset render only once each file to avoid these conflicts?

canton7 commented 11 years ago

Casset renders each group only once, by disabling a group after it's been rendered. This means you must be adding the same file to the same group multiple times? Yeah I can see that going wrong. I think I'd prefer to prevent the second instance of the file being added to the group, if that makes sense?

hammat commented 11 years ago

Yes, the file is hadded several times in the same group (js by default). I had a look in add_asset to do it inside but because of multidimensional arrays, I didn't wanted to make the code too complex.

I can have another look if you want. Still it might be more overkill.

canton7 commented 11 years ago

Hmm? I was thinking of something along the lines of

if (in_array($files, static::$groups[$type][$group]['files']))
    return;

around about line 555?

hammat commented 11 years ago

Hey sorry mate for my late answer. It's a way nicer solution you have, I agree.

It looks like your in_array condition works properly when added just before the array_push.

if (!in_array($files, static::$groups[$type][$group]['files']))
    array_push(static::$groups[$type][$group]['files'], $files);