gantry / gantry5

:rocket: Next Generation Template / Theme Framework
http://gantry.org
1.03k stars 204 forks source link

Make Resources CSS/JS Optionable-Controlable #350

Closed federone closed 9 years ago

federone commented 9 years ago

Hi,

All template developers want to control resources (to load them or not to load them), i mean CSS/JAVASCRIPT files. If we check site source, based on hyrogen template, those are:

/media/gantry5/assets/css/font-awesome.min.css
/media/gantry5/engines/nucleus/css-compiled/nucleus.css
/templates/g5_hydrogen/custom/css-compiled/hydrogen.css
/templates/g5_hydrogen/custom/css-compiled/hydrogen-joomla.css
/templates/g5_hydrogen/custom/css-compiled/custom.css
/media/gantry5/assets/css/bootstrap-gantry.css
/media/gantry5/engines/nucleus/css-compiled/joomla.css
/media/jui/css/icomoon.css

media/gantry5/assets/js/html5shiv-printshiv.min.js
/media/gantry5/engines/nucleus/css/nucleus-ie9.css
/media/gantry5/assets/js/matchmedia.polyfill.js
/media/gantry5/assets/js/main.js

bootstrap.min.js - in "root/libraries/gantry5/classes/Gantry/Framework/Theme.php" on line 89

you will say that we can override engine twig files in "custom" folder, but it is and will be very annoying to to check those files on each gantry update. for example when i checked those files from gantry beta5 to rc2, those files was completely different, and it broke whole site.

In future those files may change and it will be very annoying for us/developers and our customers to recheck those files. So can you please add in template adminside, somewhere in options a switcher button for developers where we could turn off those unwanted css/scripts? i'm sure it will be very easy for you guys, and very useful and time-saving for us.

for example, we dont want to load "media/gantry5/assets/js/main.js" script, so we have to override "page.html.twig" file, we have to remove line 60 in "templates/g5_hydrogen/custom/engine/templates/page.html.twig" file. on that line is written this:

<script type="text/javascript" src="{{ url('gantry-assets://js/main.js') }}"></script>

is it possible to load it as option, i mean to have something like this:

{% if optionToLoadMainJS %}
<script type="text/javascript" src="{{ url('gantry-assets://js/main.js') }}"></script>
{% endif %}

in "optionToLoadMainJS" i mean an option somewhere in gantry theme adminside, i dont know, somewhere to have an advanced option .... so we could turn it off, if we dont need it.

by having this: 1) it will prevent us loading the resources which we dont want to use - we, joomla template developers are always very sensitive about loading resources, for "Low Joomla site speed" issue; 2) It will save us a lot of time for future on each gantry update about checking override gantry nucleus core files;

thank you so much, Federico

mahagr commented 9 years ago

I agree on the general issue, but I would not to extend it to all core files from the engine, but to just those files which are meant to be overridden. There are some files like nucleus.css, which you should never in any circumstances modify by your own (it's the same as you changing bootstrap core files). Overrides for that file are meant to be done in template specific file. That said it would be a nice feature to be able to compile nucleus.css into your own template... But I think it's

Gantry also supports multiple Rendering Engines, so if you want to disable those core files, you could as well write a new rendering engine.

We also have no control over what Joomla wants to use; we are not loading any Joomla specific CSS/JS files by ourselves. So if you do not have any component output and you do not use any Joomla modules in the page, those files (jQuery, Bootstrap...) will not get loaded. So all of those extra assets will only be loaded by Joomla itself. And we already added an issue into Joomla tracker of loading resources it doesn't need.

w00fz commented 9 years ago

That main.js is quite fundamental for core functionalities of Gantry such as Menu and Offcanvas section. If you don't want any of that then it makes sense to override page.html.twig and just get rid of them but making them optional could just bring more issues to the table than solving any.

w00fz commented 9 years ago

I think since this is very template specific, one should just override the page.html.twig and remove the assets from loading. If a developer is building a theme from scratch, it would just not be there.