πŸ‡ΊπŸ‡ΈUnited States @wesleymusgrove

Account created on 23 August 2013, over 11 years ago
#

Merge Requests

Recent comments

πŸ‡ΊπŸ‡ΈUnited States wesleymusgrove

Very good and thanks for the link! This can be closed.

πŸ‡ΊπŸ‡ΈUnited States wesleymusgrove

I left comment #46 here https://www.drupal.org/project/drupal/issues/3105024#comment-15727018 πŸ› Drupal main javascript file can't be loaded with "defer" attribute after upgrade to 8.8.1 Fixed to describe the current state of this problem for me, now that it's recommended to uninstall AdvAgg on D10 and I still want to be able to `defer` all scripts, which was the functionality that AdvAgg Mod was providing.

πŸ‡ΊπŸ‡ΈUnited States wesleymusgrove

Unless we have many developers not using advagg that ran into this issue I don't see core are the place to fix this

Since AdvAgg is no longer recommended for D10 (and causes issues like not saving newly generated bundles of JS to disk unless you uncheck "Enable advanced aggregation" πŸ“Œ Document which parts of the module are still relevant after aggregation changes in 10.1.0 Needs review ), I've completely uninstalled it, but still needed a way to defer all JS as @nod_ mentioned in #42 πŸ› Drupal main javascript file can't be loaded with "defer" attribute after upgrade to 8.8.1 Fixed .

So I added this simple hook to `defer` all scripts:

<?php
/**
 * Implements hook_js_alter().
 */
function custom_js_alter(array &$javascript) {
  foreach ($javascript as &$js) {
    if (is_array($js) && isset($js['attributes'])) {
      $js['attributes']['defer'] = 'defer';
    } 
  }
}
?>

Before uninstalling AdvAgg, I had previously applied the core patch from #45 β†’ , which I re-rolled for D10.

After uninstalling AdvAgg and adding my `custom_js_alter` hook, I started seeing this issue happen again where Drupal behaviors weren't executing if they were attached after drupal.init.js had loaded, as would be the case for all the deferred scripts.

Since @nod_ mentioned that

it is safe to call multiple time[s]

on #38 πŸ› Drupal main javascript file can't be loaded with "defer" attribute after upgrade to 8.8.1 Fixed , would a custom module adding some JS like this to call `Drupal.attachBehaviors` one last time after the document is `complete` be an appropriate solution?

(function (Drupal, drupalSettings) {
  var domReady = function domReady(callback) {
    var readyStateCheckInterval = setInterval(function () {
      if (document.readyState === 'complete') {
        callback();
        clearInterval(readyStateCheckInterval);
      }
    }, 100);
  };

  domReady(function () {
    Drupal.attachBehaviors(document, drupalSettings);
  });
})(Drupal, window.drupalSettings);
If someone aggressively defer all scripts without using advagg I would hope they know what they are doing. the drupal.js/drupalsettings scripts are light enough to not have to defer them

I realize this technique _does_ aggressively defer all scripts and that is my goal. Is there a list of core drupal JS files that should be excluded from getting the `defer` attribute for D10 core's `Drupal.attachBehaviors` to continue working as expected even for deferred scripts that define new behaviors?

Thanks! I know this has been closed for a while, but it seemed relevant to this conversation.

πŸ‡ΊπŸ‡ΈUnited States wesleymusgrove

@tgoeg all those except for `web/libraries/choices/public/index.html` are non-functional comments essentially referencing that the polyfill code did NOT come from https://cdn.polyfill.io/v2/docs/.

While waiting on an upstream patch, @Luke.Leber mentioned over here πŸ“Œ choices/choices 9.0.1 is affected by polyfill.io Active that you can run some post composer install commands to clean it up.

I also mentioned another option in the comment below that πŸ“Œ choices/choices 9.0.1 is affected by polyfill.io Active that prevents the entire `choices/choices` library from getting downloaded in the first place. However, I think if that library doesn't exist locally on your server, then it could fallback to using the CDN library, which is the external URL that was fixed in Webform 6.2.3.

πŸ‡ΊπŸ‡ΈUnited States wesleymusgrove

Another thing you can do in composer.json is tell Composer not to even try downloading and installing the `choices/choices` library even if it is required by another package, like webform's `composer.libraries.json`. This is informing Composer that I already have a package that replaces the functionality of all versions of `choices/choices` (even though I don't have a replacement). So, Composer will not attempt to download and install `choices/choices`..

"replace": {
    "choices/choices": "*"
}
πŸ‡ΊπŸ‡ΈUnited States wesleymusgrove

Hi @ndewhurst

I wanted to provide an update based on what one of my colleagues is experiencing. It seems like the `drupal_image` Twig Tweak function does not support the `bf://uri-to-bf-image` protocol and only allows images to load from `public://uri-to-sites-default-files-image`. This might be related to an existing issue where stream wrappers are needed to load any image outside of the normal `public://` directory?

See:
https://www.drupal.org/forum/support/module-development-and-code-questio... β†’
https://www.drupal.org/project/drupal/issues/1308152 ✨ Add stream wrappers to access extension files Needs work

However, if we use the file id `fid` of the mirrored Drupal entity Brandfolder image reference, `drupal_image` is able to load that. In tandem with responsive images, this creates a picture tag with a bunch of responsive options for the image size.

Because of this, we are thinking we'll likely need to create some sort of twig function or preprocess hook that takes a Brandfolder asset id and turns it into an entity id.

It's either that or we try to use the Imagecache External β†’ Twig filter function to load the absolute URLs of Brandfolder images from the CDN link.

I'm interested in your thoughts on that approach and what the pros/cons are of not using the `bf://uri-to-bf-image` protocol?

Thanks!

πŸ‡ΊπŸ‡ΈUnited States wesleymusgrove

Hi @ndewhurst,

Thanks for the quick response and helpful tips!

Related to @cbrand02's questions, I'm looking at this article https://medium.com/geekculture/responsive-image-optimization-with-media-... and am curious if you could provide any feedback on how the Brandfolder module could be used in conjunction with the Easy Responsive Images β†’ module regarding defining and using a set of responsive image styles defined in Drupal?

Also if we're rendering Brandfolder images in our own custom twig templates, how do you recommend that be integrated with Twig Tweak β†’ and the ability to specify attributes that control whether the image is lazy loaded or eagerly preloaded ✨ Add lazy loading example in Cheat Sheet Fixed , i.e. for important images that need priority for Google Core Web vitals and Largest Contentful Paint reasons?

Thanks!
Wesley

Production build 0.71.5 2024