2

I'm trying to prevent Joomla! 3.4.1 from loading certain default scripts in the front-end template when a custom component is displayed. I am excluding the scripts in the template index.php file as follows:

unset($this->_scripts[JURI::root(true).'/media/jui/js/bootstrap.min.js']);
unset($this->_scripts[JURI::root(true).'/media/jui/js/jquery.min.js']);
unset($this->_scripts[JURI::root(true).'/media/jui/js/jquery-noconflict.js']);

Printing the contents of the $this->scripts array to the screen shows that it is empty on views generated by the component, but it has values and works as expected on all default Joomla! pages.

How can you stop scripts from loading within custom component screens in Joomla! 3.4.1?

  • @ContextSwitch I don't believe so. That question shows a variation of the solution I posted above which works on earlier version of Joomla!, but not the most recent version. In the template's index.php file, JFactory::getDocument() === $this – Zachary Draper Jun 24 '15 at 2:12
  • 1
    Are you using the same extensions? I know that when I use FLEXIcontent it overrides the template. I personally find this plugin: joomla-extensions.kubik-rubik.de/jcc-js-css-control to be the most reliable fix – iamrobert Jun 24 '15 at 3:19
  • @iamrobert Thank you for the suggestion. I will look at this, though I don't like relying on plugins to fix template issues as it is one more thing that must be installed and configured each time the template is installed. – Zachary Draper Jun 24 '15 at 4:26
  • 1
    @iamrobert Your suggestion did give me another place to investigate. I found that these files are only loaded when a page is displayed that is part of a custom component. All other pages (standard Joomla! content pages) work as expected. – Zachary Draper Jun 24 '15 at 4:34
3

It is generally a component that overrides the template files as you discovered. I personally build my sites of Zurb Foundation 5 - so I'm always removing bootstrap.

So I would look at:

  1. Overriding the component and the code it generates - however this is usually a core file that will be overwritten when you upgrade the component

  2. Custom plugin - see discussion here: How can I completely remove Bootstrap from the frontend of Joomla?

  3. jcc-js-css-control plugin (https://joomla-extensions.kubik-rubik.de/jcc-js-css-control) - which is the most reliable and simplest way I have found.

You may also need to do preg_replace for some inline js/css in your template: Joomla 3 - Tooltips

  • Prefer option 2 and often make other adjustments – jdog Jun 24 '15 at 19:30

Not the answer you're looking for? Browse other questions tagged or ask your own question.