PHPackages                             chrgriffin/laravel-defer - 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. [Framework](/categories/framework)
4. /
5. chrgriffin/laravel-defer

ActiveLibrary[Framework](/categories/framework)

chrgriffin/laravel-defer
========================

Automatically defer loading your images until after page load in Laravel.

v1.0.2(7y ago)11811MITPHPPHP &gt;=5.5.9

Since Oct 22Pushed 6y ago1 watchersCompare

[ Source](https://github.com/ChrGriffin/laravel-defer)[ Packagist](https://packagist.org/packages/chrgriffin/laravel-defer)[ RSS](/packages/chrgriffin-laravel-defer/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (3)Versions (4)Used By (0)

Laravel Defer
=============

[](#laravel-defer)

laravel-defer is a package that will automatically take ordinary image tags in your Blade templates and defer their loading. All you need to do is turn it on and embed the script!

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

[](#installation)

You can install via composer:

```
composer install chrgriffin/laravel-defer

```

This package supports auto discovery, so if you are using Laravel 5.6 or higher, you're done!

If not, you need to add the service provider to your providers array in `config/app.php`:

```
ChrGriffin\LaravelDefer\LaravelDeferServiceProvider
```

You may also find it helpful to add the Facade to your array of aliases:

```
'LaravelDefer' => ChrGriffin\LaravelDefer\Facades\LaravelDefer::class
```

You can also publish the configuration to your `config` folder:

```
php artisan vendor:publish

```

Usage
-----

[](#usage)

Once installed, you will likely need to clear your compiled views:

```
php artisan view:clear

```

If you load any page now, you will likely see that you have no images at all - this is because you need to include the script to display them. You can use either the package class, or the Blade directive:

```
@deferJS

// or:

echo ChrGriffin\LaravelDefer\LaravelDefer::js();
```

By default, the `js()` method will echo a JavaScript function called `loadDeferredImages()`, surrounded by `` tags. You can alter this behaviour in your configuration file:

```
return [
    'function_name'    => 'bananas',
    'with_script_tags' => false
];
```

You can also alter this behaviour within your application code (this will override any configs):

```
LaravelDefer::setFunctionName('bananas');
LaravelDefer::setWithScriptTags(false);
```

The last step is to call the `loadDeferredImages()` method (or whatever you called yours) wherever you need to in your JavaScript.

```
$(document).ready(function () {
    loadDeferredImages();
});
```

Skipping Templates or Images
----------------------------

[](#skipping-templates-or-images)

In the configuration file, you can specify Blade templates to skip when running the compiler:

```
'ignored_paths' => [
    '/resources/views/mail', // this will skip all Blade templates inside the mail folder
    '/resources/views/nope.blade.php' // this will skip this specific template
],
```

You can also specify specific images to skip when compiling:

```
'ignored_images' => [
    'https://i.warosu.org/data/vr/img/0021/46/1420008946756.jpg', // this will skip this particular image
    'https://i.warosu.org/', // this will skip all images from this URL
    '1420008946756.jpg' // this will skip any image with this filename
],
```

Under the Hood
--------------

[](#under-the-hood)

This package extends the application's Blade compiler with its own. The custom compiler finds all `` tags and moves their `src` attribute to a `data-ldsrc` attribute instead. Later, the `loadDeferredImages()` method finds all elements with this attribute and moves it back into the `src` attribute.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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

3

Last Release

2758d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/90b61f51551a66c90c131f873fb94ee87a064cb72dc178d8512e90e13dc769e6?d=identicon)[ChrGriffin](/maintainers/ChrGriffin)

---

Top Contributors

[![ChrGriffin](https://avatars.githubusercontent.com/u/10466686?v=4)](https://github.com/ChrGriffin "ChrGriffin (27 commits)")

---

Tags

frameworklaraveldeferdefer imagesdefer image loadingimage loading

### Embed Badge

![Health badge](/badges/chrgriffin-laravel-defer/health.svg)

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

###  Alternatives

[graham-campbell/markdown

Markdown Is A CommonMark Wrapper For Laravel

1.3k7.1M64](/packages/graham-campbell-markdown)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.5k25.9M107](/packages/laravel-cashier)[rebing/graphql-laravel

Laravel wrapper for PHP GraphQL

2.2k7.1M26](/packages/rebing-graphql-laravel)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k12.1M99](/packages/laravel-pulse)[laravel/lumen-framework

The Laravel Lumen Framework.

1.5k26.2M709](/packages/laravel-lumen-framework)[graham-campbell/manager

Manager Provides Some Manager Functionality For Laravel

39221.1M134](/packages/graham-campbell-manager)

PHPackages © 2026

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