avoiding patching header_required.php in order to skip loading C5's JS & CSS in public mode

Permalink
As many others here on this forum, I noticed that C5's own JS & CSS, needed for the Dashboard to run, is always loaded - even in public mode, making the site unnecessary heavy for regular visitors. And as many others, I also found a way of overriding & patching header_required.php to conditionally load that JS & CSS only for logged-in users.

However, I see a few issues with this approach. First of all, I found out the hard way that often suggested condition

if ($u->isRegistered()) {
  $this->addHeaderItem($html->css('ccm.base.css'), 'CORE');
  ...
}


is not actually correct, because for example a Login page also needs this JS, and having it missed results in JS errors... I'm not sure how to correctly determine the need of system Javascript, but ATM I settled on the following check:

if ($c->isEditMode() || $c->cIsSystemPage) {
  $this->addHeaderItem($html->css('ccm.base.css'), 'CORE');
  ...
}


But I might still miss some points here.

Secondly, as I naturally copied my patched version of header_required.php to /elements from /concrete/elements, thus avoiding losing of my patch during upgrades, with this I also lose potential adjustments to header_required.php code that can come with newer C5 versions. Or I have to always remember to manually compare these files when upgrading, or using diffs etc... Inconvenient.

So, what does the community think - isn't it a common idea to skip loading C5's own JS & CSS in public mode? Can developers consider it in future versions? Or, alternatively, give us developers finer control on <head> contents WITHOUT overriding the whole header_required.php? Does it make sense?

snobo
 
jordanlev replied on at Permalink Reply
jordanlev
I don't think all the system JS and CSS is loaded when not logged in. Just jquery (which is utilized by many themes and addons so you should probably leave it I'm in) and a very small amount of c5-specific code.
But if you're having problems with page load speed, search the forums for the MISER plugin, which does an excellent job of making things faster (in my experience).
snobo replied on at Permalink Reply
snobo
well, it's three files ccm.base.js, ccm.base.css and jquery.js that are loaded. Three extra requests and 40K. It may seem as not a big deal for a modern world, but if you see how narrow bandwidth is, e.g., in China (prolly due to the Big Chinese firewall), every http request counts.

What for jQuery library itself, well, I'm personally not using readymade themes, I'm laying out everything I need from scratch, so for simple sites I might not need it. And even if I do, I'd better load it from Google CDN, so again, I'd prefer to have more control on what and how I am loading. Like currently I do:

if ($c->isEditMode() || $c->cIsSystemPage) {
   $this->addHeaderItem($html->css('ccm.base.css'), 'CORE');
   $this->addHeaderItem($html->javascript('jquery.js'), 'CORE');
   $this->addHeaderItem($html->javascript('ccm.base.js', false, true), 'CORE');
} else {
   echo '<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type=”text/javascript"></script>';
}


Anyway, thanks for that MISER tip, looks interesting!