2.4 KiB
Executable File
HopCDN Client for Django
django-hopcdn is a lightweight Django library that simplifies loading CSS frameworks from your own CDN. It reads a manifest file served by the CDN to resolve the correct hashed filenames and generates <link>
tags using a simple template tag.
📚 Table of Contents
✅ Features
- 📦 Loads hashed/minified CSS from your CDN using a manifest
- 🚀 Simple
{% hopcdn_stylesheet 'name' %}
tag for easy integration - ⚡ In-memory caching for performance (thread-safe)
- 🛠️ Fallback-safe if manifest is missing or incomplete
- 🧱 Easy to extend or override
🛠️ Installation
pip install django-hopcdn
Add to INSTALLED_APPS
:
INSTALLED_APPS = [
...,
'django_hopcdn',
]
🚀 Quick Start
1. Configure settings
Add the CDN base URL in your settings.py
:
CDN_URL = "https://cdn.hopsenn.com/"
Your CDN must expose a manifest.json
at:
https://cdn.hopsenn.com/manifest.json
Example manifest.json
:
{
"main": "main.ab12cd.css",
"theme": "theme.f8d33e.css"
}
2. Use the template tag
In your template:
{% load hopcdn_tags %}
{% hopcdn_stylesheet 'main' %}
{% hopcdn_stylesheet 'theme' %}
This will render:
<link rel="stylesheet" href="https://cdn.hopsenn.com/styles/main/main.ab12cd.css">
<link rel="stylesheet" href="https://cdn.hopsenn.com/styles/theme/theme.f8d33e.css">
⚙️ Notes & Behavior
-
The manifest is fetched only once per server process and cached in memory.
-
If a key is missing or the CDN is unreachable, the tag will output a helpful comment like:
<!-- hopcdn: 'main' not found in manifest -->
-
The expected file structure on your CDN is:
/manifest.json /styles/<name>/<filename-from-manifest>
📄 License
This project is licensed under the MIT License. See the LICENSE file for details.
🤝 Contributing
Contributions are welcome! Open issues or pull requests on Git.