As a Themer / Architect, it's nice to utilize core's jquery.once.js for front end functions and design. It appears now that this core script is not loaded for anonymous users anymore as it was in Drupal 7. Can that be confirmed?

I poked through a bunch of core D8 code but did not necessarily see where any permissions are imposed on it. I do see where it gets loaded in system.module though. I'm wondering if there is a new way to additionally load this for anonymous users? Should I handle it at the theme layer and simply do an if statement in my theme's .theme file?

Possibly related:
#1541860: Reduce dependency on jQuery
#2120457: Add test to guarantee that the Standard profile does not load any JavaScript for anonymous users on critical pages

Comments

nod_’s picture

The fact that there is no js for anonymous users is not a restriction it's a consequence of not having any javascript needed on that page.

jquery, once and all the usual scripts are still available the only difference now is that you need to explicitly tell they are a dependency of your script by declaring your script in hook_library_info().

The change notice should make things a bit clearer as well: https://drupal.org/node/1764252

There is an issue to make the declaration nicer as well, so you might not by required to write PHP down the line to declare you libraires.

Danny Englander’s picture

That works nicely, thanks! However, what about this issue: #1996238: Replace hook_library_info() by *.libraries.yml file ? It sounds like hook_library_info will be going away? I see a lot of use of it in core though and my IDE, PHPStorm does not show it as depreciated.

nod_’s picture

Yeah it won't be depreciated. It'll be removed altogether. All core use of the hook will be replaced by library.yml files at the same time.

Danny Englander’s picture

So maybe not the right place to ask but would I declare a .library.yml file in a config folder within my theme? i.e. MYTHEME.library.yml? Or is this something I need to wait for the API to catch up with first? Thanks.

nod_’s picture

i'd stick with the hook for now. the patch still has a long way to go and the exact contents of the yml file are not set in stone.

I don't think it'd be in a config folder, it will most likely end up at the same level as mytheme.info.yml

nod_’s picture

oh and please keep posting questions. I'm really eager to know how contrib see and deal with the changes we made. there is still time to fix things :)

Danny Englander’s picture

Status: Active » Fixed

Thanks for all your help and insight. I have a bevy of issues I've documented here: https://drupal.org/project/gratis#d8.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.