jQuery position, why do we HAVE to have it in the header, and how can i move it just for Guests?


So as usual Concrete5 requires jQuery to be loaded up top. Fine. In 5.6 we could edit the header_required with some logic to move it into the footer when a Guest is viewing the page, to help speed things up and keep search engines happier.

But, in 5.7 it seems to have moved to a config file, and whatever you set is the same rule for every user. Meaning I either have a slower load time for my users, or I can't use the edit features of conrete5 when logged in, as if jQuery is in the footer it breaks.

Is there a way to define different positions based on the current User, is there any available logic which can be pulled in?

I can't seem to get the User class in to the app.php file.

namespace Application\Config\App;
use Concrete\Core\User;
$u = new User();
if (!$u->isRegistered()) { //if they are not logged in
   $pos = 'F';
   $pos = 'H';
return array(
    'assets' => array(
        'jquery' => array(

Class 'Concrete\Core\User' not found

Any ideas?

View Replies:
AndyJ replied on at Permalink Reply
If you configure the page_theme.php in your theme so that it provides jquery can't you then use page level logic to decide where it is included?
MrKDilkington replied on at Permalink Reply
Hi pixelhero,

You can load jQuery in the footer conditionally, but doing that will break blocks that use it. It isn't ideal, but the 33KB GZIP'ed jQuery in your head is necessary.

The alternative is using blocks that don't use jQuery or have been modified to wait until jQuery is loaded to execute. Doing something like this is not trivial, but will depend on your site audience. If you are serving users in developing countries who have low quality mobile connections or that most users who visit your site are on mobile, then it is something to explore. If not, I am not sure if it is worth the effort.
pixelhero replied on at Permalink Reply
I'm not using any blocks that require jQuery, it's simply the concrete5 editor that stops working, the overlays get lost so I cant click on anything to edit it.

I will exclude it from the theme config and simply include it in the footer when the user is not logged in. Seems the most reliable way.

Thanks guys
MrKDilkington replied on at Permalink Reply

In your theme page_theme.php, you can do something like this:
$c = \Page::getCurrentPage();
$currentPermissions = new \Permissions($c);
$user = new \User;
if ($currentPermissions->canViewToolbar() || $user->isLoggedIn()) {
    $this->requireAsset('javascript', 'jquery');
} else {
    $this->providesAsset('javascript', 'jquery');

- if the current user can view the toolbar or is logged in, concrete5 will load jQuery
- if not, you provide jQuery in your theme