Hey,

It would be cool if there was support for additional CDN's.

At a bare minimum I would love to be able to use:
* http://cdnjs.com/
* http://code.jquery.com/

Perhaps even being able to add a custom CDN/list of CDN's to load from?

Also, being able to select which version of each package you want to load (and maybe even from which CDN) would be cool/

Cheers,

Glenn

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

johnv’s picture

IMO this is supported,
See /admin/config/development/jquery_update .

ericduran’s picture

Yep, I agree. These 2 CDNs aren't currently in the list.

Patches welcome.

lunatic’s picture

Version: 7.x-2.x-dev » 7.x-3.x-dev
Issue summary: View changes
Status: Active » Needs review
FileSize
1.92 KB

hi

here is a patch to support CDNjs in the 3.x branch

AFAIK code.jquery.com is already supported

lunatic’s picture

here is a patch for 2.7 stable version

mrP’s picture

@lunatic for 3.x, it looks like its missing jquery migrate -- https://cdnjs.com/libraries/jquery-migrate

amme’s picture

markhalliwell’s picture

Title: Support multiple CDN's » Better CDN support
Status: Needs review » Needs work

This is going to be a catch all issue for all related CDN requests.

markhalliwell’s picture

Title: Better CDN support » Better CDN/API/automation support

I really think that this "including jQuery source files in this project" is getting really old and tedious. It makes the project bloated and a maintenance burden. Not to mention ginormous "patches".

I'd really like to add support for https://www.drupal.org/project/libraries_cdn, which could help automate a LOT of this module's code.

The unfortunate downside is that it depends on 3 additional modules, which would make 4 for just this one and the biggest advantage of this module is that you can install it and (most of the time) it "just works".

---

I still really like the idea of parsing an API, which we can do with the jsDelivr API as it already supports querying against all the CDN's this module supports.

This would allow us to get rid of static versions entirely and avoid the whole "jQuery Update is stale" problem we seem to have quite a lot of.

We could even save the selected CDN choice(es) to the filesystem for "local backup" like it's currently done, but just using Drupal's file API (e.g. sites/default/files, etc).

This would essentially allow us to remove ALL of the source files currently committed in the repo and would, effectively, shut down the concerns made in #1857042: [jquery_update] 3rd party libraries.

---

Also, I actually already implemented something very similar like this in the Bootstrap base theme and it's been wildly successful :D.

You can see the various functions used for this at https://drupal-bootstrap.org/api/bootstrap/includes%21cdn.inc/7

markhalliwell’s picture

As was discovered in #2860158: Re-add jQuery Form 4.2.1, we'll also need a way to exclude certain versions that we know are 100% incompatible with Drupal from being selected.

markhalliwell’s picture

Priority: Normal » Major

This needs to happen

mcdruid’s picture

https://github.com/jsdelivr/api has been deprecated and replaced by https://github.com/jsdelivr/data.jsdelivr.com

The latter doesn't seem to support the same list of CDNs for jQuery as the former project did; seems like it's now limited to npm (and github).

Looking at all the jQuery libraries this project covers (UI, migrate, form) all seem to be offered by https://cdnjs.com (which is backed / powered by Cloudflare).

There's a also quite a fully-featured API which looks like it could do everything that'd be needed for jQuery Update e.g.

$ curl -s https://api.cdnjs.com/libraries/jquery?fields=versions | jq
{
  "versions": [
    "1.10.0",
    "1.10.1",
    "1.10.2",

...snip - a lot of other releases...

    "3.4.0",
    "3.4.1",
    "3.5.0",
    "3.5.1"
  ]
}

$ curl -s https://api.cdnjs.com/libraries/jquery/3.5.1 | jq
{
  "name": "jquery",
  "version": "3.5.1",
  "rawFiles": [
    "jquery.js",
    "jquery.min.js",
    "jquery.min.map",
    "jquery.slim.js",
    "jquery.slim.min.js",
    "jquery.slim.min.map"
  ],
  "files": [
    "jquery.js",
    "jquery.min.js",
    "jquery.min.map",
    "jquery.slim.js",
    "jquery.slim.min.js",
    "jquery.slim.min.map"
  ],
  "sri": {
    "jquery.js": "sha512-WNLxfP/8cVYL9sj8Jnp6et0BkubLP31jhTG9vhL/F5uEZmg5wEzKoXp1kJslzPQWwPT1eyMiSxlKCgzHLOTOTQ==",
    "jquery.min.js": "sha512-bLT0Qm9VnAYZDflyKcBaQ2gg0hSYNQrJ8RilYldYQ1FxQYoCLtUjuuRuZo+fjqhx/qtq/1itJ0C2ejDxltZVFg==",
    "jquery.slim.js": "sha512-1lagjLfnC1I0iqH9plHYIUq3vDMfjhZsLy9elfK89RBcpcRcx4l+kRJBSnHh2Mh6kLxRHoObD1M5UTUbgFy6nA==",
    "jquery.slim.min.js": "sha512-/DXTXr6nQodMUiq+IUJYCt2PPOUjrHJ9wFrqpJ3XkgPNOZVfMok7cRw6CSxyCQxXn6ozlESsSh1/sMCTF1rL/g=="
  }
}

It also has:

$ curl -s https://api.cdnjs.com/libraries/jqueryui?fields=versions | jq
{
  "versions": [
    "1.10.0",
    "1.10.1",
    "1.10.2",
    "1.10.3",
    "1.10.4",
    "1.11.0",
    "1.11.1",
    "1.11.2",
    "1.11.3",
    "1.11.4",
    "1.12.0",
    "1.12.0-beta.1",
    "1.12.0-rc.1",
    "1.12.0-rc.2",
    "1.12.1",
    "1.8.13",
    "1.8.16",
    "1.8.17",
    "1.8.18",
    "1.8.19",
    "1.8.21",
    "1.8.23",
    "1.8.24",
    "1.9.0",
    "1.9.1",
    "1.9.2"
  ]
}
$ curl -s https://api.cdnjs.com/libraries/jquery-migrate?fields=versions | jq
{
  "versions": [
    "1.0.0",
    "1.1.0",
    "1.1.1",
    "1.2.0",
    "1.2.1",
    "1.3.0",
    "1.4.0",
    "1.4.1",
    "3.0.0",
    "3.0.0-rc1",
    "3.0.1",
    "3.1.0",
    "3.2.0",
    "3.3.0",
    "3.3.1"
  ]
}
$ curl -s https://api.cdnjs.com/libraries/jquery.form?fields=versions | jq
{
  "versions": [
    "3.09",
    "3.19",
    "3.20",
    "3.24",
    "3.25.0-2013.01.18",
    "3.32",
    "3.32.0-2013.04.09",
    "3.36",
    "3.37.0",
    "3.45",
    "3.45.0",
    "3.46",
    "3.46.0",
    "3.49",
    "3.50",
    "3.51",
    "4.0.0",
    "4.0.1",
    "4.1.0",
    "4.2.0",
    "4.2.1",
    "4.2.2",
    "4.3.0"
  ]
}

Looking at the existing CDN support, it looks like none of the supported options have a version of jQuery Form, and I don't think google hosts jQuery Migrate. The microsoft CDN now seems to be redirecting some URLs.

If the idea was to get all of the jQuery files from a CDN, cdnjs may be only one that covers everything and it has the API.

markhalliwell’s picture

jsDelivr is actually far more comprehensive than cdnjs, if only because cdnjs requires manual updates (or hope the entry setup autoupdates).

Their new API is a little misleading, while it appears it's only for NPM, they're just using NPM as a registry (same for GH); that's all.

It allows new packages/versions to be served near instantaneously.

It does lack in the "search" aspect, but that's mainly because they have actively deferred/recommended to use other services that allow you to search NPM or GH using those services APIs.

Once you know the package name on NPM or the user/repo on GH, you can use jsDelivr's API and CDN just fine.

It does take a little work as they split their API into two different URLs:

Retrieve available package versions:
https://data.jsdelivr.com/v1/package/npm/:name

https://data.jsdelivr.com/v1/package/npm/jquery

Retrieve available package files for a given version:
https://data.jsdelivr.com/v1/package/npm/:name@:version
https://data.jsdelivr.com/v1/package/npm/jquery@3.5.1

Finally, once you know the file path from above, you have to prepend it with the appropriate CDN prefix (sadly this isn't as intuitive from the API, but it works once you know it follows the same structure, just with a different domain):
https://cdn.jsdelivr.net/npm/:name@:version/:path
https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js

---

FWIW, Drupal Bootstrap has been using jsDelivr as it's CDN backend for many years now.

mcdruid’s picture

FileSize
12.44 KB

This is certainly not pretty, but here's a patch (against 7.x-3.x) which allows arbitrary paths / versions for:

  • jQuery itself
  • jquery-ui
  • jquery.cookie
  • jquery.form
  • jquery-migrate

There's no UI at present and it's easy to break things quite badly, but the idea is that sites can get different versions of all of the above either from a CDN from a local path.

Some examples that can be placed in settings.php

$conf['jquery_update_custom_path_jquery'] = 'https://code.jquery.com/jquery-3.6.0.js';
$conf['jquery_update_custom_version_jquery'] = '3.6.0';
$conf['jquery_update_custom_path_jqueryui'] = '/sites/default/files/jquery_update/jquery-ui.js';
$conf['jquery_update_custom_version_jqueryui'] = '1.13.0';
$conf['jquery_update_custom_path_cookie'] = 'https://cdn.jsdelivr.net/gh/carhartl/jquery-cookie@1.4.1/jquery.cookie.js';
$conf['jquery_update_custom_version_jquery_cookie'] = '1.4.1';
$conf['jquery_update_custom_path_form'] = 'https://cdn.jsdelivr.net/gh/jquery-form/form@4.2.1/dist/jquery.form.min.js';
$conf['jquery_update_custom_version_jquery_form'] = '4.2.1';
$conf['jquery_update_custom_path_migrate'] = 'https://cdn.jsdelivr.net/npm/jquery-migrate@3.3.2/dist/jquery-migrate.min.js';
$conf['jquery_update_custom_version_jquery_migrate'] = '3.3.2';

With those settings everything is fetched from a CDN except for jquery-ui which comes from a local copy saved in the files directory.

It should be possible to use local copies of everything, get everything from one or more CDNs, or a mix of both.

All of these are optional so you omit any settings you don't want to customise.

This is pretty rough around the edges, but is hopefully a start in the direction of not having to commit copies of every plugin / library as it gets an update etc..

The module does quite a bit of mapping different versions against each other, and that's mostly bypassed with these custom settings. Caution is advised.

At the moment you have to set a couple of extra variables / settings for all of the custom settings to "kick in". For example - something like:

jquery_update_jquery_migrate_enable: true
jquery_update_jquery_version: 3.6 // anything above 1.9

You also have to set the themes you want to use jquery_update to "Site default".

Anyone able to test this out?

mcdruid’s picture

Status: Needs work » Closed (outdated)

The functionality outlined in the most recent comment is now in 7.x-4.x where any ongoing changes will be made.