PHPackages                             senyahnoj/laravel-sri - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. senyahnoj/laravel-sri

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

senyahnoj/laravel-sri
=====================

Subresource Integrity hash generator for laravel

3.4.1(7mo ago)074MITPHPPHP ^7.3 | ^7.4 | ^8.0CI passing

Since Oct 8Pushed 7mo agoCompare

[ Source](https://github.com/senyahnoj/laravel-sri)[ Packagist](https://packagist.org/packages/senyahnoj/laravel-sri)[ RSS](/packages/senyahnoj-laravel-sri/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (4)Versions (4)Used By (0)

Laravel Subresource Integrity
=============================

[](#laravel-subresource-integrity)

[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![StyleCI](https://camo.githubusercontent.com/2da809632a4467a58d09381ec6f99d79f531e946ef21c91eeefb2259e95e4f4a/68747470733a2f2f7374796c6563692e696f2f7265706f732f3131393739313836312f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/119791861)[![GitHub Workflow Status](https://camo.githubusercontent.com/fbfd533a4c97eab5843931fd8232369422a1b68ca49f91576d61838bfd889d95/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f656c6865626572742f6c61726176656c2d7372692f52756e253230504850556e697425323074657374733f6c6162656c3d5465737473267374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/fbfd533a4c97eab5843931fd8232369422a1b68ca49f91576d61838bfd889d95/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f656c6865626572742f6c61726176656c2d7372692f52756e253230504850556e697425323074657374733f6c6162656c3d5465737473267374796c653d666c61742d737175617265)[![Latest Version on Packagist](https://camo.githubusercontent.com/982341d6d8f6497578c2e81ab53948a82551843612ba2078b1e2d3a7d67e84f8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656c6865626572742f6c61726176656c2d7372692e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/elhebert/laravel-sri)[![Total Downloads](https://camo.githubusercontent.com/15cd06df6e3961d61d3ab7d65c3e21feaf15105df5e9ea9dcdc8be6cfaa5c773/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f656c6865626572742f6c61726176656c2d7372692e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/elhebert/laravel-sri)

Small Laravel 8+ package that'll generate the integrity hashes for your style and script files.

For Laravel 5.5+ support, use the [v1 branch](https://github.com/Elhebert/laravel-sri/tree/v1). For Laravel 6+ support, use the [v2 branch](https://github.com/Elhebert/laravel-sri/tree/v2).

About Subresources Integrity
----------------------------

[](#about-subresources-integrity)

From [MDN](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity):

> Subresource Integrity (SRI) is a security feature that enables browsers to verify that files they fetch (for example, from a CDN) are delivered without unexpected manipulation. It works by allowing you to provide a cryptographic hash that a fetched file must match.

Troy Hunt wrote an article speaking on the subject, you can read it [here](https://www.troyhunt.com/protecting-your-embedded-content-with-subresource-integrity-sri/)

Installation
------------

[](#installation)

```
composer require elhebert/laravel-sri
```

This package uses [auto-discovery](https://laravel.com/docs/5.5/packages#package-discovery), so you don't have to do anything. It works out of the box.

Config
------

[](#config)

If you want to make changes in the configuration you can publish the config file using

```
php artisan vendor:publish --provider="Elhebert\SubresourceIntegrity\SriServiceProvider"
```

### Content of the configuration

[](#content-of-the-configuration)

keydefault valuepossible valuesbase\_path`base_path('/public')`algorithmsha256sha256, sha384 and sha512hashes`[]`(see "[How to get a hash](#how-to-get-a-hash))mix\_sri\_path`public_path('mix-sri.json')`(see "[How to get a hash](#how-to-get-a-hash))enabled`true`dangerously\_allow\_third\_party\_assets`false`Usage
-----

[](#usage)

To only get a hash, use `Sri::hash`:

```

```

To generate the HTML for the `integrity` and the `crossorigin` attributes, use `Sri::html`. It accepts two parameters:

- first one is the path;
- second one (default is `false`) tells if you want to pass the credentials when fetching the resource.

```

```

### Blade Component

[](#blade-component)

Alternatively you can use blade components:

```

```

If you add a `mix` attributet to the component it'll use `mix()` instead of `asset()` to generate the link to the assets:

```

```

### Improve performance

[](#improve-performance)

You should wrap your `` and `` tags with the [`@once`](https://laravel.com/docs/master/blade#the-once-directive) directive to ensure that your tags are only rendered once. This will help with performances as it'll avoid a potential re-hashing of the files (in case you want to hash them on the fly).

Be careful that this should only be use for production as it won't re-render the html tag. Thus preventing new cache busting id to be added to the path by `mix`.

```
@once

@endonce
```

How to get a hash
-----------------

[](#how-to-get-a-hash)

### Store hashes in the configuration

[](#store-hashes-in-the-configuration)

You can references the assets in the configuration like this:

```
[
    // ...

    'hashes' => [
        'css/app.css' => 'my_super_hash'
        'https://code.jquery.com/jquery-3.3.1.min.js' => 'sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8='
    ]
]
```

This means, you have to calculate the hashes yourself. To do this, you can use [report-uri.io](https://report-uri.com/home/sri_hash), [mozilla hash generator](https://www.srihash.org/) or any other resource available.

### Using a webpack (or Mix) plugin to generate hashes on build

[](#using-a-webpack-or-mix-plugin-to-generate-hashes-on-build)

It expect a `mix-sri.json` file with a similar structure to the `mix-manifest.json`:

```
{
    "/css/app.css": "my_super_hash",
    "/js/app.js": "my_super_hash"
}
```

The filename and path can be changed in the configuration at any time.

> Self promotion: I made a Laravel Mix extension [laravel-mix-sri](https://github.com/Elhebert/laravel-mix-sri) for this purpose.

### Generate them on the fly

[](#generate-them-on-the-fly)

If it can't find the asset hash in the config file nor in the mix-sri.json file, it'll generate the hash on each reload of the page.

This method is the least recommended, because it reduce performance and make your page load slower.

Remote resources
----------------

[](#remote-resources)

This package also work for remote resources. Be careful that resources like Google Fonts [won't work](https://github.com/google/fonts/issues/473).

```

```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for more details.

License
-------

[](#license)

This project and the Laravel framework are open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance64

Regular maintenance activity

Popularity10

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

216d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e25d54a6581b428c66b13103d12c5d65ea91a6b5673989a9a78fa55bb70d198c?d=identicon)[senyahnoj](/maintainers/senyahnoj)

---

Top Contributors

[![Elhebert](https://avatars.githubusercontent.com/u/3165079?v=4)](https://github.com/Elhebert "Elhebert (22 commits)")[![owenvoke](https://avatars.githubusercontent.com/u/1899334?v=4)](https://github.com/owenvoke "owenvoke (6 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (6 commits)")[![juliomotol](https://avatars.githubusercontent.com/u/21353103?v=4)](https://github.com/juliomotol "juliomotol (4 commits)")[![senyahnoj](https://avatars.githubusercontent.com/u/5585851?v=4)](https://github.com/senyahnoj "senyahnoj (4 commits)")[![FrancaR](https://avatars.githubusercontent.com/u/54752465?v=4)](https://github.com/FrancaR "FrancaR (3 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")[![HDVinnie](https://avatars.githubusercontent.com/u/12850699?v=4)](https://github.com/HDVinnie "HDVinnie (1 commits)")[![Glennmen](https://avatars.githubusercontent.com/u/11406433?v=4)](https://github.com/Glennmen "Glennmen (1 commits)")[![Dylan-DPC](https://avatars.githubusercontent.com/u/99973273?v=4)](https://github.com/Dylan-DPC "Dylan-DPC (1 commits)")[![PanjiNamjaElf](https://avatars.githubusercontent.com/u/16651293?v=4)](https://github.com/PanjiNamjaElf "PanjiNamjaElf (1 commits)")[![phenixdotnet](https://avatars.githubusercontent.com/u/2082554?v=4)](https://github.com/phenixdotnet "phenixdotnet (1 commits)")[![dmitrijivanenko](https://avatars.githubusercontent.com/u/10165801?v=4)](https://github.com/dmitrijivanenko "dmitrijivanenko (1 commits)")[![thirsch](https://avatars.githubusercontent.com/u/1055937?v=4)](https://github.com/thirsch "thirsch (1 commits)")

---

Tags

srisubresource-integritylaravel-sri

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/senyahnoj-laravel-sri/health.svg)

```
[![Health](https://phpackages.com/badges/senyahnoj-laravel-sri/health.svg)](https://phpackages.com/packages/senyahnoj-laravel-sri)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[elhebert/laravel-sri

Subresource Integrity hash generator for laravel

40225.5k](/packages/elhebert-laravel-sri)[illuminate/pipeline

The Illuminate Pipeline package.

9446.6M213](/packages/illuminate-pipeline)[illuminate/pagination

The Illuminate Pagination package.

10532.5M862](/packages/illuminate-pagination)[spatie/laravel-mix-preload

Add preload and prefetch links based your Mix manifest

169176.0k2](/packages/spatie-laravel-mix-preload)[mrmarchone/laravel-auto-crud

Laravel Auto CRUD helps you streamline development and save time.

28711.8k2](/packages/mrmarchone-laravel-auto-crud)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
