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 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 hollyit/filament-static-assets 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Asset Management for PHP
g4 application profiler package
CSS/Javascript Minificator, Compressor and Concatenator for TYPO3 - highly configurable frontend asset optimization for CSS/JS merging, minification and compression with optional body parsing, async/defer loading, inline output, data-ignore exclusions, SRI integrity validation/calculation, external
WordPress mu-plugin to remove jQuery Migrate from the list of jQuery dependencies and to allow jQuery to enqueue before </body> instead of in the <head>.
Caching and compression for Twig assets (JavaScript and CSS).
Create link to static resources with cache-breaking segment based on md5 of the file
统计信息
- 总下载量: 12.93k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 15
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-09-10