定制 hollyit/filament-static-assets 二次开发

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

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

hollyit/filament-static-assets

Composer 安装命令:

composer require hollyit/filament-static-assets

包简介

Improved handling of stylesheets and javascript files for Filament

README 文档

README

This package aims to solve improve the static asset handling of the amazing Laravel package Filament.

NOTE: This package is for Filament served assets only. If you are looking for a general Laravel asset management system that includes the same features as this, plus advanced dependency management, then the newly released Laravel Static Libraries might be of interest.

By default Filament serves all static files (js and css) via Laravel. While this method is perfectly fine for smaller projects, it can become a performance hit once your project grows. To overcome the performance hit, this package will copy all your static assets to a path in your public directory, thereby allowing your webserver to directly handle the files. If you add a package with new files and forget run the command, no sweat, things will fallback directly to Filament's default handling.

Another feature of the caching mechanism is the addition of cache buster keys added to the actual URLs. These keys are based off of the filemtime of the original asset file, so even if you republish, browser caching will remain untouched.

To cache your static files, just run this simple command:

 php artisan filament:cache-assets

And to clear the files out, going back to the original method of handling files:

 php artisan filament:flush-assets

One problem with this method is that you may easily forget to run the commands when packages are updated. Therefor it is highly recommended to add a script to your composer.json file to handle this automatically:

    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-update-cmd": [
            "@php artisan vendor:publish --tag=laravel-assets --ansi --force",
            "@php artisan filament:upgrade",
            "@php artisan filament:cache-assets" // Add this line
        ],

        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    },

The second problem this package deals with is the loading of assets on every page. As projects grow and more static assets are added, this can be another performance hit. If you use a package like the Filament Tiptap Editor or Filament Tiny Editor, then those files load on every page, regardless of you needing them or not. To stop this, there are two events fired when rendering out scripts and stylesheets:

HollyIT\FilamentStaticAssets\Events\PreProcessStaticAssetsEvent

This event is fired before the files are processed and things like cache busting keys are added.

HollyIT\FilamentStaticAssets\Events\PostProcessStaticAssetsEvent

This event fires after all alterations are done to the files and ready to be rendered in the template.

Both methods expose the same properties:

$event->files is a collection of the actual files. So in the PreProcess event, you could remove a script file: $event->files->forget('file_to_drop');

$event->domain is the scope of the files. This can be either styles, scripts or beforeCoreScripts

Install

composer require hollyit/filament-static-assets

One Note!

To make all this possible, this package has to override the FilamentManager class provided by Filament. So If you are trying to do anything extra with that concrete class, keep in mind you'll have to echo the changes made by this class.

Testing

This package is fully tested with 100% coverage.

License

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

hollyit/filament-static-assets 适用场景与选型建议

hollyit/filament-static-assets 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12.93k 次下载、GitHub Stars 达 15, 最近一次更新时间为 2022 年 09 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 hollyit/filament-static-assets 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 12.93k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 15
  • 点击次数: 13
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 15
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-09-10