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.
Class 'Concrete\Core\User' not found
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?
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.
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.
In your theme page_theme.php, you can do something like this:
- if the current user can view the toolbar or is logged in, concrete5 will load jQuery
- if not, you provide jQuery in your theme