Name | flask-cache-manifest JSON |
Version |
1.0.4
JSON |
| download |
home_page | |
Summary | Flask extension to serve md5 hashed assets via manifest file. |
upload_time | 2023-08-20 04:22:41 |
maintainer | |
docs_url | None |
author | Maxime Dupuis |
requires_python | >=3.7 |
license | MIT |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
|
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![PyPI pyversions](https://img.shields.io/pypi/pyversions/flask-cache-manifest.svg)](https://pypi.python.org/pypi/flask-cache-manifest/)
[![Platforms](https://img.shields.io/badge/platform-Linux,_MacOS,_Windows-blue)]()
[![PyPI version fury.io](https://badge.fury.io/py/flask-cache-manifest.svg)](https://pypi.python.org/pypi/flask-cache-manifest/)
[![GitHub Workflow Status (with event)](https://github.com/pySourceSDK/ValveBSP/actions/workflows/CI.yml/badge.svg)]()
[![Coverage](https://github.com/maxdup/flask-cache-manifest/blob/master/docs/source/coverage.svg "coverage")]()
# Flask-Cache-Manifest
Flask-cache-manifest is a [Flask](https://flask.palletsprojects.com/en/2.2.x/) extension to help you serve your md5 hashed assets. Having file hashes in filenames is a popular feature of modern asset bundlers. It's a good strategy for browser cache busting. However, Flask does not provide an easy way to reference those complicated and ever-changing filenames. Flask-cache-manifest lets you reference those assets by leveraging `cache_manifest.json` files.
Full Documentation: https://maxdup.github.io/flask-cache-manifest/
Turns:
```Jinja
<link type="text/css" rel="stylesheet"
href="{{ hashed_url_for('static', filename='css/app.css') }}">
```
into:
```html
<link type="text/css" rel="stylesheet"
href="/static/css/app-d41d8cd98f00b204e9800998ecf8427e.css">
```
## Installation
```
pip install flask-cache-manifest
```
## Initializing
The extension needs to be loaded alongside your Flask application.
Here's how it's done:
```python
from flask import Flask, Blueprint
from flask_cache_manifest import FlaskCacheManifest
flaskCacheManifest = FlaskCacheManifest()
app = Flask('my-app',
static_folder='dist/static',
static_url_path='/static')
bp = Blueprint('my-blueprint',
__name__,
static_folder='blueprints/static',
static_url_path='/bp/static')
app.register_blueprint(bp)
flaskCacheManifest.init_app(app)
app.run()
```
**_NOTE:_**
Ideally, `flaskCacheManifest.init_app` needs to be called after you've registered your blueprints.
Static folders registered after `init_app` will not be loaded.
## Usage
Flask-cache-manifest adds the `hashed_url_for` function for use in your templates.
It is analogous to Flask's url_for. Given the above example and its blueprints,
here's how you would be able to reference your static files in your Jinja templates.
```html
<!-- from the app's static folder -->
<link type="text/css" rel="stylesheet"
href="{{ hashed_url_for('static', filename='css/app.css') }}">
<!-- from the blueprint's static folder -->
<link type="text/css" rel="stylesheet"
href="{{ hashed_url_for('my-blueprint.static', filename='css/app.css') }}">
<!-- from the static folder relative to what is currently being rendered -->
<link type="text/css" rel="stylesheet"
href="{{ hashed_url_for('.static', filename='css/app.css') }}">
Raw data
{
"_id": null,
"home_page": "",
"name": "flask-cache-manifest",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "",
"author": "Maxime Dupuis",
"author_email": "mdupuis@hotmail.ca",
"download_url": "https://files.pythonhosted.org/packages/78/c2/250e9e7deab8c3a71c19ead8ef5358b6a7a9b2d879a01daeb18914fe020f/flask-cache-manifest-1.0.4.tar.gz",
"platform": "any",
"description": "[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![PyPI pyversions](https://img.shields.io/pypi/pyversions/flask-cache-manifest.svg)](https://pypi.python.org/pypi/flask-cache-manifest/)\n[![Platforms](https://img.shields.io/badge/platform-Linux,_MacOS,_Windows-blue)]()\n[![PyPI version fury.io](https://badge.fury.io/py/flask-cache-manifest.svg)](https://pypi.python.org/pypi/flask-cache-manifest/)\n[![GitHub Workflow Status (with event)](https://github.com/pySourceSDK/ValveBSP/actions/workflows/CI.yml/badge.svg)]()\n[![Coverage](https://github.com/maxdup/flask-cache-manifest/blob/master/docs/source/coverage.svg \"coverage\")]()\n\n# Flask-Cache-Manifest\n\nFlask-cache-manifest is a [Flask](https://flask.palletsprojects.com/en/2.2.x/) extension to help you serve your md5 hashed assets. Having file hashes in filenames is a popular feature of modern asset bundlers. It's a good strategy for browser cache busting. However, Flask does not provide an easy way to reference those complicated and ever-changing filenames. Flask-cache-manifest lets you reference those assets by leveraging `cache_manifest.json` files.\n\n\nFull Documentation: https://maxdup.github.io/flask-cache-manifest/\n\nTurns:\n```Jinja\n<link type=\"text/css\" rel=\"stylesheet\"\n href=\"{{ hashed_url_for('static', filename='css/app.css') }}\">\n```\n\ninto:\n\n```html\n<link type=\"text/css\" rel=\"stylesheet\"\n href=\"/static/css/app-d41d8cd98f00b204e9800998ecf8427e.css\">\n```\n\n\n## Installation\n\n```\npip install flask-cache-manifest\n```\n\n\n## Initializing\n\nThe extension needs to be loaded alongside your Flask application.\n\nHere's how it's done:\n\n```python\n\nfrom flask import Flask, Blueprint\nfrom flask_cache_manifest import FlaskCacheManifest\n\nflaskCacheManifest = FlaskCacheManifest()\n\napp = Flask('my-app',\n static_folder='dist/static',\n static_url_path='/static')\n\nbp = Blueprint('my-blueprint',\n __name__,\n static_folder='blueprints/static',\n static_url_path='/bp/static')\n\napp.register_blueprint(bp)\n\nflaskCacheManifest.init_app(app)\n\napp.run()\n```\n\n**_NOTE:_**\n Ideally, `flaskCacheManifest.init_app` needs to be called after you've registered your blueprints.\n Static folders registered after `init_app` will not be loaded.\n\n\n## Usage\n\nFlask-cache-manifest adds the `hashed_url_for` function for use in your templates.\nIt is analogous to Flask's url_for. Given the above example and its blueprints,\nhere's how you would be able to reference your static files in your Jinja templates.\n\n```html\n<!-- from the app's static folder -->\n<link type=\"text/css\" rel=\"stylesheet\"\n href=\"{{ hashed_url_for('static', filename='css/app.css') }}\">\n\n<!-- from the blueprint's static folder -->\n<link type=\"text/css\" rel=\"stylesheet\"\n href=\"{{ hashed_url_for('my-blueprint.static', filename='css/app.css') }}\">\n\n<!-- from the static folder relative to what is currently being rendered -->\n<link type=\"text/css\" rel=\"stylesheet\"\n href=\"{{ hashed_url_for('.static', filename='css/app.css') }}\">\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Flask extension to serve md5 hashed assets via manifest file.",
"version": "1.0.4",
"project_urls": {
"Documentation": "https://maxdup.github.io/flask-cache-manifest/",
"Github": "https://github.com/maxdup/flask-cache-manifest"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "de29ca043728febe8504885fa7f9b3bd4a1a7d9036b2b309993a5958ca3a2f47",
"md5": "69a3d6a2fd6defe34e0543ed23607ac0",
"sha256": "3342d2fa3f0c91c6d1e915e6687245afac1a739e1322aa633d16cfcda5adf2fc"
},
"downloads": -1,
"filename": "flask_cache_manifest-1.0.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "69a3d6a2fd6defe34e0543ed23607ac0",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 5587,
"upload_time": "2023-08-20T04:22:40",
"upload_time_iso_8601": "2023-08-20T04:22:40.412436Z",
"url": "https://files.pythonhosted.org/packages/de/29/ca043728febe8504885fa7f9b3bd4a1a7d9036b2b309993a5958ca3a2f47/flask_cache_manifest-1.0.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "78c2250e9e7deab8c3a71c19ead8ef5358b6a7a9b2d879a01daeb18914fe020f",
"md5": "a1e627afd382706e8b7c648917dd71e2",
"sha256": "40db6de5273a87a576c7a3d4efe70fb7d196eb45619d4b4dab8edcaeeaa30bb7"
},
"downloads": -1,
"filename": "flask-cache-manifest-1.0.4.tar.gz",
"has_sig": false,
"md5_digest": "a1e627afd382706e8b7c648917dd71e2",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 5177,
"upload_time": "2023-08-20T04:22:41",
"upload_time_iso_8601": "2023-08-20T04:22:41.952113Z",
"url": "https://files.pythonhosted.org/packages/78/c2/250e9e7deab8c3a71c19ead8ef5358b6a7a9b2d879a01daeb18914fe020f/flask-cache-manifest-1.0.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-08-20 04:22:41",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "maxdup",
"github_project": "flask-cache-manifest",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"requirements": [],
"tox": true,
"lcname": "flask-cache-manifest"
}