Problem/Motivation

In our project, we are working on a JS refactor to improve performance and we have detected that colorbox libraries are globally loaded in all pages even though it is not being used in all of them.

Proposed resolution

Change the way of loading libraries to detect if they are needed.

Comments

abarrio created an issue. See original summary.

jody lynn’s picture

I am also seeing the library loaded globally. Is this a bug in how the library is being attached?

jody lynn’s picture

Cancel that. This was a self-inflected wound on this project in my case, not a colorbox issue

paulocs’s picture

Category: Bug report » Support request
Status: Active » Reviewed & tested by the community

I don't see any way how to reproduce this issue. I debug the code and I notice that the library is attached in the ColorboxFormatter::viewElements() function:

// Attach the Colorbox JS and CSS.
if ($this->attachment->isApplicable()) {
  $this->attachment->attach($elements);
}

This function is called when the field is rendered only. So the library is not loaded in all pages by the module...

See also: https://git.drupalcode.org/project/colorbox/-/commit/a3b5e85f901e0b668e56f3277843f3102c3a9e5b

renatog’s picture

Status: Reviewed & tested by the community » Fixed

Yeah, really makes sense. I think it's ok. I recommend only make sure that you're using the last version and try to clear all cachess and turn-on the minification on JS

Thank you so much everyone

Status: Fixed » Closed (fixed)

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