https://github.com/sjelfull/craft-sri
Generate the SRI (Subresource Integrity Hash) for remote JS/CSS files.
https://github.com/sjelfull/craft-sri
craftcms craftcms-plugin
Last synced: about 1 year ago
JSON representation
Generate the SRI (Subresource Integrity Hash) for remote JS/CSS files.
- Host: GitHub
- URL: https://github.com/sjelfull/craft-sri
- Owner: sjelfull
- License: mit
- Created: 2016-03-20T13:12:59.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-02-23T22:56:18.000Z (over 9 years ago)
- Last Synced: 2025-03-24T21:05:11.759Z (over 1 year ago)
- Topics: craftcms, craftcms-plugin
- Language: PHP
- Size: 11.7 KB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# SRI plugin for Craft CMS
Generate the SRI (Subresource Integrity Hash) for remote JS/CSS files.
## Installation
To install SRI, follow these steps:
1. Download & unzip the file and place the `sri` directory into your `craft/plugins` directory
2. -OR- do a `git clone https://github.com/sjelfull/Craft-SRI.git` directly into your `craft/plugins` folder. You can then update it with `git pull`
3. Install plugin in the Craft Control Panel under Settings > Plugins
4. The plugin folder should be named `sri` for Craft to see it. GitHub recently started appending `-master` (the branch name) to the name of the folder for zip file downloads.
SRI works on Craft 2.4.x and Craft 2.5.x.
## SRI Overview
SRI is a new W3C specification that allows web developers to ensure that resources hosted on third-party servers have not been tampered with. Use of SRI is recommended as a best-practice, whenever libraries are loaded from a third-party source.
Learn more about how to use [subresource integrity](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity) on MDN.
## Using SRI
You can apply the `sri` filter to either a `` or a `<link>` tag, like so:
```{{ '<script src="https://code.jquery.com/jquery-2.1.4.min.js">' | sri }}```
```{{ '' | sri }}```
The request will be cached for 24 hours. You may override this in general.php by setting the duration like so:
```php
'sriCacheDuration' => 3600 * 24, // 24 hours by default
```
## SRI Roadmap
- Add option for calculating hashes with multiple algorithms
- Add support for multiple tags inside filter section
- ~~Make cache duration configurable.~~
## SRI Changelog
### 1.0.0 -- 2016.03.20
* Initial release
Brought to you by [Fred Carlsen](http://sjelfull.no)