[5.8] Making the frontend lean by disabling C5-injected jQuery and CSS

Permalink
I've been struggling for a while now to remove the following lines from my header:
<link href="/concrete/css/app.css" rel="stylesheet" type="text/css" media="all">
<link href="/concrete/css/account.css" rel="stylesheet" type="text/css" media="all">
<script type="text/javascript" src="/concrete/js/jquery.js"></script>
<link href="/concrete/css/font-awesome.css" rel="stylesheet" type="text/css" media="all">
<link href="/concrete/css/jquery-ui.css" rel="stylesheet" type="text/css" media="all">


Documentation is a bit scarce these days about doing this in the 5.8+ world.
I'd like to include it in my header only if the user is a member of a certain group, say "Admininstrators".

VPenkov
 
ramonleenders replied on at Permalink Best Answer Reply
ramonleenders
Open up your page_theme.php (of the theme you are using). Add something like this:

public function registerAssets()
    {
       /* If a user is logged in, we can load some extras */
       $u = new User();
       if (!$u->isLoggedIn()) {
          $this->providesAsset('css', 'font-awesome');
          $this->providesAsset('css', 'jquery/ui');
          $this->providesAsset('css', 'core/account');
          $this->providesAsset('javascript', 'jquery');
          $this->providesAsset('javascript', 'jquery/ui');
       } else {
        // Do something else?
       }
 }


If not logged in, it will say you provide these assets yourself, so it will not add them for you automatically. Bear in mind that jQuery stuff will be broken if you don't include jQuery yourself. So be sure to do that. I split the css/javascript, so you can see the difference.

You can open concrete/config/app.php to see which assets are all defined (under the 'assets' key of this file).
VPenkov replied on at Permalink Reply
VPenkov
Thanks, that's perfect. Concrete5 even handles on its own the cases where the toolbar is present and autoincludes jQuery so I can ignore the user logic.
It's all blazing-fast now. Just some reference for everyone who stumbles upon this.
BTW, I also had to re-activate my theme so C5 can find my page_theme.php.
<?php
namespace Application\Theme\MyThemeFolderName;
use Concrete\Core\Area\Layout\Preset\Provider\ThemeProviderInterface;
class PageTheme extends \Concrete\Core\Page\Theme\Theme {   
    public function registerAssets() {
        $this->providesAsset('css', 'font-awesome');
        $this->providesAsset('css', 'jquery/ui');
        $this->providesAsset('css', 'core/account');
        $this->providesAsset('javascript', 'jquery');
        $this->providesAsset('javascript', 'jquery/ui');
    }
}