Option to Load Leaflet JavaScript Locally Instead of CDN (GDPR Compliance)

Created on 24 February 2025, about 1 month ago

Hello,

I am currently using the Leaflet module, but I noticed that it loads JavaScript and CSS files from an external CDN (unpkg.com or cdnjs) by default. This raises GDPR concerns, as it may result in data transfer to third-party servers.

My questions:

Is there an existing option in the module to load Leaflet.js and Leaflet.css locally instead of from a CDN?
If not, would you consider adding a setting that allows users to choose between CDN and local hosting for better compliance with privacy regulations?
As a possible workaround, I would try to replace the CDN version by manually adding local files to my custom theme like this:

Download Leaflet.js and Leaflet.css and store them in:
📂 themes/custom/my_theme/libraries/leaflet/

Define a custom library in my_theme.libraries.yml:

yaml
Kopieren
leaflet_local:
css:
theme:
libraries/leaflet/leaflet.css: {}
js:
libraries/leaflet/leaflet.js: {}
dependencies:
- core/drupal
Force Drupal to load the local version in my_theme.theme:

function my_theme_preprocess_page(&$variables) {
$variables['#attached']['library'][] = 'my_theme/leaflet_local';
}
Before I proceed with this workaround, I wanted to ask if there is already a built-in option to achieve this within the module? Or is there a better solution? There used to be a patch for the Drupal 7 module, but I haven’t found one for the new version yet. Thanks for your support!

Bavra

Feature request
Status

Needs work

Version

10.2

Component

Code

Created by

🇩🇪Germany bavramor

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

Comments & Activities

  • Issue created by @bavramor
  • 🇩🇪Germany bavramor

    Hello,

    I am currently using the Leaflet module, but I noticed that it loads JavaScript and CSS files from an external CDN (unpkg.com or cdnjs) by default. This raises GDPR concerns, as it may result in data transfer to third-party servers.

    My questions:

    Is there an existing option in the module to load Leaflet.js and Leaflet.css locally instead of from a CDN?
    If not, would you consider adding a setting that allows users to choose between CDN and local hosting for better compliance with privacy regulations?
    As a possible workaround, I would try to replace the CDN version by manually adding local files to my custom theme like this:

    Download Leaflet.js and Leaflet.css and store them in:
    📂 themes/custom/my_theme/libraries/leaflet/

    Define a custom library in my_theme.libraries.yml:

    leaflet_local:
      css:
        theme:
          libraries/leaflet/leaflet.css: {}
      js:
        libraries/leaflet/leaflet.js: {}
      dependencies:

    - core/drupal
    Force Drupal to load the local version in my_theme.theme:

    function my_theme_preprocess_page(&$variables) {
      $variables['#attached']['library'][] = 'my_theme/leaflet_local';
    }

    Before I proceed with this workaround, I wanted to ask if there is already a built-in option to achieve this within the module? Or is there a better solution? There used to be a patch for the Drupal 7 module, but I haven’t found one for the new version yet. Thanks for your support!

    Bavra

  • 🇮🇹Italy itamair

    Hey @bavramor what are you referring and looking into?
    What you state here looks totally wrong ...

    Did you ever inspect the Drupal Leaflet module libraries definitions?
    And in particular the leaflet/leaflet library definition one here (?):
    https://git.drupalcode.org/project/leaflet/-/blob/10.2.x/leaflet.librari...

    leaflet:
      remote: http://leafletjs.com/
      version: 1.9.4
      license:
        name: Leaflet-License
        url: https://github.com/Leaflet/Leaflet/blob/v1.9.4/LICENSE
        gpl-compatible: true
      js:
        js/leaflet/dist/leaflet.js: {}
      css:
        component:
          js/leaflet/dist/leaflet.css: {}
    

    All is indeed (already) being embedded in the module itself and loaded from it.

    And if not (if it wasn't the case) you should know that you could always implement your own hook_library_info_alter() and alter it in your own way ...
    (rather than defining and adding a new my_theme.libraries.yml, kind of un-appropriate).

    Further more you could have also better inspected already existing Drupal leaflet module issues and easily found that GDPR issues / matters have already been discussed in this existing fixed issue:
    https://www.drupal.org/project/leaflet/issues/3086698 Use Leaflet GDPR conform Active

    Please, make your deep(er) investigation and inspection of all these things before opening new issues, that look so far from reflecting the actual version of the Drupal Leaflet module (because everybody time is precious ... ).

    Confident all this helps and points you in the proper direction ... and happy Drupal use & contribution too
    (sorry to mention, but your longstanding Drupal profile looks still soo sadly empty on that side).

  • 🇩🇪Germany bavramor

    You're right, I somehow took a wrong turn in my thoughts—I promise to do better. My mistake, but thank you for the really quick feedback; it truly wasn't a waste of time. You really helped me a lot with that. Bavra

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

Production build 0.71.5 2024