I have Kirby set up using the suggested Multi-environment configs from the docs .
Development environment config:
/site/config/config.dev.mydomain.com.php
Production environment config:
/site/config/config.mydomain.com.php
I’m looking to have different asset path for each environment.
Development environment asset path:
/assets/dev/
Production environment asset path:
/assets/prod/
What’s the best way to set the different asset paths inside each config?
texnixe
November 3, 2018, 3:22pm
#2
I think the easiest way to do that, is via a config setting:
E.g. in /site/config/config.dev.mydomain.com.php
c::set('assets.path', 'dev');
In your header
<?= css('assets/' . c::get('assets.path', 'prod') . '/app.min.css') ?>
Note that I’ve used prod
as a fallback value here, in case the assets path is not set. Instead of only setting the subfolder, you can of course set the path to assets/dev' etc. instead and modify the
css()`helper accordingly.
This is great! Thank you! I didn’t think it would be as easy as that.
Are there any downsides to using this technique as you start to use it for more and more assets? - say I’m using this for 50 assets on a page?
texnixe
November 3, 2018, 3:52pm
#4
I don’t see any downsides; the only downside is loading 50 assets per page.
alistairtweedie:
50 assets on a page
My hint:
Use less or sass to avoid so many css-files! Google is your friend for details…
[Added:]
May be you want to use different snippet files header.php
, one for each environment.
Yes, 50 assets would be a bit extreme I was more concerned if there were any speed issues on Kirby’s side as this method isn’t “the norm” I guess.
FYI, I’m using Gulp to compile assets for both environments. When I compile for production these assets are minified and uglified before deployed.
Anyway, thank you for all your help
texnixe
November 3, 2018, 4:57pm
#7
No, speed-wise, I think the call to the config setting is the last thing you need to be concerned about. If you use it multiple times in a template, I’d store the value in a variable, anyway.
1 Like