Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment | File | Size | Author |
---|---|---|---|
#13 | 1869928-13.patch | 12.44 KB | mcdruid |
#4 | 1869928-support-cdnjs-4.patch | 1.77 KB | lunatic |
#3 | 1869928-support-cdnjs-3.patch | 1.92 KB | lunatic |
Comments
Comment #1
johnvIMO this is supported,
See /admin/config/development/jquery_update .
Comment #2
ericduran CreditAttribution: ericduran commentedYep, I agree. These 2 CDNs aren't currently in the list.
Patches welcome.
Comment #3
lunatic CreditAttribution: lunatic commentedhi
here is a patch to support CDNjs in the 3.x branch
AFAIK code.jquery.com is already supported
Comment #4
lunatic CreditAttribution: lunatic commentedhere is a patch for 2.7 stable version
Comment #5
mrP CreditAttribution: mrP commented@lunatic for 3.x, it looks like its missing jquery migrate -- https://cdnjs.com/libraries/jquery-migrate
Comment #6
amme CreditAttribution: amme commentedComment #7
markhalliwellThis is going to be a catch all issue for all related CDN requests.
Comment #8
markhalliwellI 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
Comment #9
markhalliwellAs 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.
Comment #10
markhalliwellThis needs to happen
Comment #11
mcdruidhttps://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.
It also has:
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.
Comment #12
markhalliwelljsDelivr 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.
Comment #13
mcdruidThis is certainly not pretty, but here's a patch (against 7.x-3.x) which allows arbitrary paths / versions for:
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
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:
You also have to set the themes you want to use jquery_update to "Site default".
Anyone able to test this out?
Comment #14
mcdruidThe functionality outlined in the most recent comment is now in 7.x-4.x where any ongoing changes will be made.