ADVAGG_CDN is not available for drupal 10

Created on 25 August 2023, over 1 year ago
Updated 5 August 2024, 5 months ago

Problem/Motivation

ADVAGG_CDN is not available for drupal 10

Steps to reproduce

Install composer require 'drupal/advagg:^6.0@alpha'
Enable all the advagg module and try to access the same
Check for CDN tab , it was available for drupal 8/9 but not for D10.
I started working for D10 update , have dependency for the same.
Can you please help me on that how can we use this module for D10 ?

🐛 Bug report
Status

Needs review

Version

6.0

Component

CDN

Created by

🇮🇳India ishwar

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @ishwar
  • 🇺🇸United States luke adams

    I know this post is a little old, however, if you're just trying to load the jquery.min.js file from Google's CDN, the following will work. Can be placed in any custom module you've got.

    
    /**
     * Implements hook_js_alter().
     */
    function MY_MODULE_js_alter(&$javascript) {
      $module_handler = \Drupal::service('module_handler');
      $advagg_exists = $module_handler->moduleExists('advagg_cdn');
    
      if ($advagg_exists) {
        return;
      }
    
      // Modified from advagg_cdn module.  This module was removed from 6.0 version.
      // Get JQuery from Google cdn.
      $jquery_lib = 'core/assets/vendor/jquery/jquery.min.js';
      if (!empty($javascript[$jquery_lib])) {
        $url = 'https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js';
        $javascript[$jquery_lib]['type'] = 'external';
        $javascript[$jquery_lib]['data'] = $url;
        $javascript[$jquery_lib]['version'] = '3.5.1';
      }
    }
    
  • Status changed to Needs review 5 months ago
  • 🇮🇳India vinai_katiyar Delhi NCR

    Hi @ishwar,
    The submodule AddAvg CDN is removed under the release 6.0.0-alpha1 version.
    To resolve their dependency in Drupal10 , you can use hook_js_alter() and hook_css_alter().

    Example Using hook_js_alter()

    <?php
    /**
     * Implements hook_js_alter().
     */
    function my_module_js_alter(&$javascript) {
      // Replace with your CDN URL
      $cdn_url = 'https://your-cdn.com';
    
      // Target specific JavaScript file
      $jquery_lib = 'core/assets/vendor/jquery/jquery.min.js';
    
      // Check if the specific JavaScript file is set
      if (!empty($javascript[$jquery_lib])) {
        // Replace the local path with the CDN path
        $javascript[$jquery_lib]['data'] = $cdn_url . '/jquery.min.js';
      }
    }
    
    ?>
    

    Example Using hook_cs_alter()

    <?php
    /**
     * Implements hook_css_alter().
     */
    function my_module_css_alter(&$css) {
      // Replace 'https://your-cdn-domain.com' with your actual CDN domain
      $cdn_url = 'https://your-cdn-domain.com';
    
      // Target a specific CSS file in your module
      $my_css_file = 'modules/custom/my_module/css/my_styles.css';
    
      // Check if the specific CSS file is set
      if (isset($css[$my_css_file])) {
        // Replace the local path with the CDN path
        $css[$my_css_file]['data'] = $cdn_url . '/path/to/your/css/file.css';
      }
    }
    
    ?>
    
Production build 0.71.5 2024