Deregistration of ConcreteCMS assets (e.g. jquery)

Hi! I’m developing a simple ConcreteCMS theme. How I can disable or deregister some CSS/JS assets from header and footer? I’m developing a simple website, which does not need e.g. Jquery and Vuejs libraries when user is not logged in. I’m using Bedrock, and I have these codes in header and footer:
Header:

    <?php
    View::element('header_required', [
        'pageTitle' => $pageTitle ?? '',
        'pageDescription' => $pageDescription ?? '',
        'pageMetaKeywords' => $pageMetaKeywords ?? ''
    ]);
    ?>

Footer:
<?php Loader::element('footer_required'); ?>

And also, head and footer looks like this on website:

Head:

<link href="/concrete/css/fontawesome/all.css?ccm_nocache=70d00a1d2c448be40b04d5240ea1ebca23358dbb" rel="stylesheet" type="text/css" media="all">
<script type="text/javascript" src="/concrete/js/jquery.js?ccm_nocache=70d00a1d2c448be40b04d5240ea1ebca23358dbb"></script>
<link href="/concrete/css/features/imagery/frontend.css?ccm_nocache=70d00a1d2c448be40b04d5240ea1ebca23358dbb" rel="stylesheet" type="text/css" media="all">
<link href="/concrete/css/features/navigation/frontend.css?ccm_nocache=70d00a1d2c448be40b04d5240ea1ebca23358dbb" rel="stylesheet" type="text/css" media="all">

Footer:

<script type="text/javascript" src="/concrete/js/vue.js?ccm_nocache=70d00a1d2c448be40b04d5240ea1ebca23358dbb"></script>
<script type="text/javascript" src="/concrete/js/bootstrap.js?ccm_nocache=ecd20c5ca7bb1e84c9c0911c07fcb0df9a019416"></script>
<script type="text/javascript" src="/concrete/js/moment.js?ccm_nocache=70d00a1d2c448be40b04d5240ea1ebca23358dbb"></script>
<script type="text/javascript" src="/ccm/assets/localization/moment/js"></script>
<script type="text/javascript" src="/concrete/js/features/imagery/frontend.js?ccm_nocache=70d00a1d2c448be40b04d5240ea1ebca23358dbb"></script>
<script type="text/javascript" src="/concrete/js/features/navigation/frontend.js?ccm_nocache=70d00a1d2c448be40b04d5240ea1ebca23358dbb"></script>

Thank you already for help!

To anyone reading, akismet had originally marked this as spam. Looks like it is genuine.

For your theme, first make sure you are looking at the header and footer when not logged in and no blocks are requiring assets.

Create a page with noting on it save one block of text. Other blocks could be pulling in the assets, which are then loaded in the page header or footer. Then log out. When logged in, many assets are loaded by the dashboard toolbar and panels.

Then reassess the assets loaded by the header and footer.

Hello, thank you. I noted that ConcreteCMS loads always jQuery, VueJS and other libraries if I add use Concrete\Core\Page\Theme\BedrockThemeTrait; to page_theme.php file. If I remove it, Concrete loads only needed libraries (as I want). Is this normal?

Bedrock is kind of layer on top of bootstrap used by Atomik and other themes and consequently provides everything big themes like Atomik needs including all block templates.

If you have a bedrock based theme, but do not pull in all its dependencies in page_theme, you need to be careful about running into unexpected behaviour later on. That is fine for your own use and risk, but would not be approved if you submitted the theme to the marketplace.

Bedrock is a heavyweight, but comes out ahead if your site is using a lot of it.

On a more practical level, if you want to create a minimal theme that does not use much of bedrock, you are probably better off not starting from bedrock. Any themes that originated pre v9 will not be bedrock based, so could be educational.

Also consider a derivative of Elemental (older bootstrap version) created using Elemental Cloner Products :: Concrete CMS Marketplace.

Alright, I don’t need Bedrock in my theme then. But, in fact, if I add e.g. a Galleryblock to my page that does not have this Bedrockthemetrait code in the page_theme.php file, jquery (or some other library what is needed for gallery) does not load (clicking on the image does not open the carousel, as it should). The gallery works when logged in. How can I make jquery work every time some content uses it?

Where a block does not load an asset on the assumption it is provided by the theme, you can either load the js or css asset with your custom theme header/footer (ie, meet the block’s assumption) or provide your own variant of the block which loads the asset (ie, remove the assumption).

Marketplace blocks generally register their requirement for all necessary assets (so the core loads them if they are not already provided by the theme or by the block). Core blocks could make the assumption that bedrock has already loaded assets.

The premise of Bedrock / Atomik (and many bigger themes) is that once assets are combined and minified, its usually more efficient to load a common combined global, hence a single bigger and less optimised asset, than to load smaller different page-optimised assets. Its heavier for first load for first time visitors, but after that the browser cache always hits.

There is a section in the docs about requiring and providing assets if you have not already read it.

About being logged in, the dashboard loads many assets. So its always best to test when logged out. When developing, I generally keep 2 browsers open. 1 logged in and 1 logged out.

1 Like