Skip to content

Fix: Vendor Leaflet JS and CSS locally to replace external CDN dependencies#114

Merged
benjaoming merged 5 commits intodjango:mainfrom
kehach07:issue-70-vender-third-party-assets
Nov 15, 2025
Merged

Fix: Vendor Leaflet JS and CSS locally to replace external CDN dependencies#114
benjaoming merged 5 commits intodjango:mainfrom
kehach07:issue-70-vender-third-party-assets

Conversation

@kehach07
Copy link
Contributor

This PR addresses issue #70 by vendoring Leaflet’s JS and CSS assets locally within the project.

Summary of Changes:
Added leaflet.js and leaflet.css files under static/vendor/leaflet/
Updated project references to use local paths instead of unpkg CDN URLs
Ensured all Leaflet functionality remains intact using the local assets

Rationale:
Improves long-term reliability by avoiding dependence on external CDNs
Mitigates privacy and security concerns related to third-party hosting
Keeps the project fully functional even in offline or long-term archival contexts

Additional Note:
I have updated the README file to include commands for easily updating to newer Leaflet versions in the future.

<!-- Leaflet Marker Cluster CSS files -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/1.4.1/MarkerCluster.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/1.5.0/MarkerCluster.Default.min.css" />
<!-- ✅ Leaflet CSS files (vendored locally) -->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think use of emojis are needed and/or meaningful here. Personally, I wouldn't even update the comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for that, sir! I’ve made meaningful updates to the PR based on your suggestions. Thank you for your feedback and response!

Comment on lines +10 to +12
<!-- ✅ Map data setup -->
<script>
const singleEventData = {{ .sigleEvent | default "null" }};
const eventsData = {
"type": "FeatureCollection",
"features": [
{{- range $index, $event := $events }}
{
"type": "Feature",
"properties": {
"name": {{ .Title }},
"slug": {{ .Slug }},
"date": {{ .Params.event_date }},
"end_date": {{ .Params.event_date_end }},
"address": {{ if eq .Params.event_type "in_person" }}{{ .Params.venue_address }}{{ else }}{{ .Params.event_type }}{{ end }},
"description": {{ .Description }},
"event_type": {{ .Params.event_type }},
"event_category": {{ .Params.event_category }},
"host": {{ .Params.event_host }},
"website": {{ .Params.event_url | default .Permalink }},
"event_category_label": {{ .Params.event_category }}
},
"geometry": {
"type": "Point",
"coordinates": [
{{ .Params.longitude }},
{{ .Params.latitude }}
]
}
}{{ if ne (add $index 1) (len $events) }},{{ end }}
{{- end }}
]
};
const singleEventData = {{ .sigleEvent | default "null" }};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not apply any formatting, or cosmetic changes like the comment wording updates. It's better to keep the diff size as small as possible and in the scope of the issue.

README.md Outdated

If a new version of Leaflet or MarkerCluster is released, you can update the vendored files using the following PowerShell commands (update version numbers as needed):

```powershell
Copy link
Member

@ulgens ulgens Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think Windows specific instructions are the best way to go here. I'm not even sure these instructions are needed, but if we are going to add something, I'd prefer having commands that uses open source tools - like wget and curl.

<!-- Leaflet CSS file -->
<link rel="stylesheet" type="text/css" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=" crossorigin="" />
<!-- Leaflet Marker Cluster CSS files -->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep this comment too.

<!-- Map -->
{{ $events := .events }}
<div id="map" aria-label="Django 20th Anniversary Event Locations"></div>
<div id="map" aria-label="Django 20th Anniversary Event Locations" style="height: 600px;"></div>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this change relate to vendored leaflet?

@ulgens
Copy link
Member

ulgens commented Nov 13, 2025

Thank you for all the updates. I have two more comments, and they will be the last ones on my side:

  • Is there an easy way to communicate the version? Only the leaflet.js file includes a header with version information; for the other files, there is no easy way to determine which version they are. I'm not recommending adding headers to other files—I think we should use them however they are originally packaged —but we may want to include a version reference in the filename or elsewhere.
  • Can you please squash the commits when all is done? Fix commits don't provide much for the history, except for creating noise.

…prepare for future version updates

Fix: vendor Leaflet JS and CSS locally to replace CDN references and prepare for future version updates

Fix: vendor Leaflet JS and CSS locally to replace CDN references and prepare for future version updates

Fix: vendor Leaflet JS and CSS locally to replace CDN references and prepare for future version updates

Fix: vendor Leaflet JS and CSS locally to replace CDN references and prepare for future version updates

Final updates before squash
@kehach07 kehach07 force-pushed the issue-70-vender-third-party-assets branch from 5ab79cd to f5e96df Compare November 13, 2025 06:23
@benjaoming benjaoming force-pushed the issue-70-vender-third-party-assets branch from d54bca8 to dc0617f Compare November 15, 2025 22:41
Copy link
Contributor

@benjaoming benjaoming left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing! Thanks for getting this in! It works well for me 👍 I made changes so it's clear what versions these originate from.

I don't think we'll be doing much maintenance work on this: From experience, once it's vendored, it stays kind of static until someone takes initiative to update it.

@benjaoming benjaoming merged commit 1ae1885 into django:main Nov 15, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants