定制 ideal-creative-lab/laravel-tachyon 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ideal-creative-lab/laravel-tachyon

最新稳定版本:v4.2.0

Composer 安装命令:

composer require ideal-creative-lab/laravel-tachyon

包简介

Laravel Tachyon is a package designed to optimize the performance of your Laravel applications by optimizing and minifying HTML output on demand.

README 文档

README

Stand With Ukraine


Laravel Tachyon Laravel Tachyon

Latest Stable Version Required PHP Version Required Laravel Version 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 dotninth/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="DotNinth\LaravelTachyon\ServiceProvider"

Middleware Registration

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

// bootstrap/app.php

return Application::configure(basePath: dirname(__DIR__))
    ...
    ->withMiddleware(function (Middleware $middleware) {
        $middleware->append([
            \DotNinth\LaravelTachyon\Middleware\RemoveComments::class,
            \DotNinth\LaravelTachyon\Middleware\CollapseWhitespace::class,
            \DotNinth\LaravelTachyon\Middleware\ElideAttributes::class,
            \DotNinth\LaravelTachyon\Middleware\InlineCss::class,
            \DotNinth\LaravelTachyon\Middleware\InsertDNSPrefetch::class,
            \DotNinth\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.
  • 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.
  • 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.

Warning

Use TrimUrls::class middleware with care, as it can cause problems if the wrong base URL is used.

Important

CollapseWhitespace::class automatically calls the RemoveComments::class middleware before executing.

Note

You can ignore minification of some elements. Add data-tachyon-ignore as an element attribute to do so.


⚙️ 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.

ideal-creative-lab/laravel-tachyon 适用场景与选型建议

ideal-creative-lab/laravel-tachyon 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 222 次下载、GitHub Stars 达 7, 最近一次更新时间为 2023 年 08 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「html」 「minify」 「laravel」 「optimize」 「page speed」 「livewire」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 ideal-creative-lab/laravel-tachyon 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 ideal-creative-lab/laravel-tachyon 我们能提供哪些服务?
定制开发 / 二次开发

基于 ideal-creative-lab/laravel-tachyon 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 222
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 24
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 1
  • Forks: 292
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-08-11