Git Product home page Git Product logo

laravel-tachyon's Introduction

Support Ukraine Support Ukraine


Latest Stable Version PHP Version Require License

Introduction

Laravel Tachyon is a powerful package designed to optimize the performance of your Laravel applications by minifying HTML output on demand. With over 35% optimization, it helps improve page load speed and overall user experience.

Laravel Tachyon supports the following:

  • Laravel Livewire: Laravel Tachyon seamlessly integrates with Laravel Livewire, allowing you to optimize the HTML output of your Livewire components.

  • Alpine JS: Laravel Tachyon is compatible with Alpine JS, ensuring that the optimization process does not interfere with the functionality of your Alpine JS components.

Additionally, Laravel Tachyon ensures that the optimization process does not break the following HTML elements:

  • <pre>: The content within <pre> tags, which is typically used for displaying preformatted text, is preserved and not modified during the optimization process.

  • <textarea>: The content within <textarea> tags, which is used for input fields that allow multiple lines of text, is also preserved and not modified.

  • <script>: The content within <script> tags, which is used for JavaScript code, is not modified by Laravel Tachyon. This ensures that your JavaScript code remains intact and functions as expected.

Getting Started

Requirements

Installation

You can install the package via composer:

composer require ideal-creative-lab/laravel-tachyon

This package supports Laravel Package Discovery.

Publish configuration file

To customize the package settings, you can publish the configuration file with the following command:

php artisan vendor:publish --provider="IdealCreativeLab\LaravelTachyon\ServiceProvider"

Middleware Registration

To enable the package functionality, make sure to register the provided middlewares in the kernel of your Laravel application. Here's an example of how to do it:

// app/Http/Kernel.php

protected $middleware = [
    ...
    \IdealCreativeLab\LaravelTachyon\Middleware\InlineCss::class,
    \IdealCreativeLab\LaravelTachyon\Middleware\ElideAttributes::class,
    \IdealCreativeLab\LaravelTachyon\Middleware\InsertDNSPrefetch::class,
    \IdealCreativeLab\LaravelTachyon\Middleware\RemoveQuotes::class,
    \IdealCreativeLab\LaravelTachyon\Middleware\CollapseWhitespace::class,
    \IdealCreativeLab\LaravelTachyon\Middleware\DeferJavascript::class,
]

Middlewares Details

  • RemoveComments::class: Removes HTML, JS, and CSS comments from the output to reduce the transfer size of HTML files.
  • CollapseWhitespace::class: Reduces the size of HTML files by removing unnecessary white space.
    • It automatically calls the RemoveComments::class middleware before executing.
    • You can ignore minification of some elements. Add data-tachyon-ignore as an element attribute to do so.
  • RemoveQuotes::class: Removes unnecessary quotes from HTML attributes, resulting in a reduced byte count on most pages.
  • ElideAttributes::class: Reduces the transfer size of HTML files by removing attributes from tags if their values match the default attribute values.
  • InsertDNSPrefetch::class: Includes <link rel="dns-prefetch" href="//www.example.com"> tags in the HTML <head> section to enable DNS prefetching, reducing DNS lookup time and improving page load times.
  • TrimUrls::class: Trims URLs by making them relative to the base URL of the page. This can help reduce the size of URLs and may improve performance.
    • โš ๏ธ Note: Use this middleware with care, as it can cause problems if the wrong base URL is used.
  • InlineCss::class: Transforms the inline style attribute of HTML tags into classes by moving the CSS into the <head> section, improving page rendering and reducing the number of browser requests.
  • DeferJavascript::class: Defers the execution of JavaScript code in HTML, prioritizing the rendering of critical content before executing JavaScript.
    • If you need to cancel the defer in some script, use data-tachyon-no-defer as a script attribute to cancel the defer.

Configuration

After installing the package, you may need to configure some options according to your needs.

Disable Service

To disable the Laravel Tachyon service in your local environment and get readable output, modify the following configuration file:

// config/laravel-tachyon.php

//Set this field to false to disable the Laravel Tachyon service.
'enable' => env('LARAVEL_TACHYON_ENABLED', true),

Skip routes

You can configure the package to skip optimization for certain routes. Use the * wildcard to match multiple routes. Here's an example:

// config/laravel-tachyon.php

//You can use * as wildcard.
'skip' => [
    '*.pdf', //Ignore all routes with final .pdf
    '*/downloads/*',//Ignore all routes that contain 'downloads'
    'assets/*', // Ignore all routes with the 'assets' prefix
];

Feel free to adjust the configuration options according to your specific needs.

Notice: By default, the package automatically skips binary and streamed responses. See the File Downloads for more information.

Testing

$ composer test

Contributing

Please see CONTRIBUTING for details.

License

The MIT License (MIT). Please see License File for more information.

laravel-tachyon's People

Contributors

renatomarinho avatar dotninth avatar joaorobertopb avatar lucasmesquitaborges avatar tswestendorp avatar stakahashi avatar vinkla avatar saifulwebid avatar kenzouno1 avatar tvbeek avatar swilla avatar laravel-shift avatar percymamedy avatar patrickbrouwers avatar nikonor909 avatar gofish543 avatar japseyz avatar carusogabriel avatar f-liva avatar lakuapik avatar caneco avatar andysnell avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.