I have made a couple of modules that loads their own stylesheet. Why I do that is because then I can optimize my website furhter and only load the stylesheet data when the module is actually on the page. But the problem is is that when I load multiple same modules but with different data it will load the stylesheet twice. Is there anything I can do to prevent that?

// Get the document object
$doc = JFactory::getDocument();

// Get the module object
$module1 = JModuleHelper::getModule('mod_commercial');

// Extract the module base path
$moduleBase = JUri::base() . 'modules/' . $module1->module . '/';

// Define the path of your CSS file dynamically
$cssFile = $moduleBase . 'css/style.css';


This is the code I use in my main module file.

  • I can't reproduce the issue. Assuming it's the same file, only one <link rel="stylesheet"...> tag appears.
    – Sharky
    Commented Feb 2 at 6:06
  • Ah i'm a bit stupid, i haven't put that in the main file but in the template file
    – Kuubs
    Commented Feb 11 at 10:58


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.