asyrafhussin/laravel-page-speed
Composer 安装命令:
composer require asyrafhussin/laravel-page-speed
包简介
Laravel Page Speed
README 文档
README
Forked From renatomarinho/laravel-page-speed
Laravel Page Speed [Support Laravel 5.7]
Simple package to minify HTML output on demand which results in a 35%+ optimization.
Installation is easy
You can install the package via composer:
$ composer search asyrafhussin/laravel-page-speed:1.8.8@dev
Laravel 5.5 and up
You don't have to do anything else, this package uses the Package Auto-Discovery feature, and should be available as soon as you install it via Composer.
Laravel 5.4 or 5.3
Add the Service Provider to your config/app.php: AsyrafHussin\LaravelPageSpeed\ServiceProvider::class
This is required for publishing the configuration file:
Publish configuration file
php artisan vendor:publish --provider="AsyrafHussin\LaravelPageSpeed\ServiceProvider"
Register Middlewares
Next, the \AsyrafHussin\LaravelPageSpeed\Middleware\CollapseWhitespace::class and other middleware must be registered in the kernel:
//app/Http/Kernel.php protected $middleware = [ ... \AsyrafHussin\LaravelPageSpeed\Middleware\InlineCss::class, \AsyrafHussin\LaravelPageSpeed\Middleware\ElideAttributes::class, \AsyrafHussin\LaravelPageSpeed\Middleware\InsertDNSPrefetch::class, \AsyrafHussin\LaravelPageSpeed\Middleware\RemoveComments::class, \AsyrafHussin\LaravelPageSpeed\Middleware\TrimUrls::class, \AsyrafHussin\LaravelPageSpeed\Middleware\RemoveQuotes::class, \AsyrafHussin\LaravelPageSpeed\Middleware\CollapseWhitespace::class, ]
Before
After
Roadmap : Filters
| Name | Description | Available |
| inline_css | Inlines small external CSS files | YES |
| elide_attributes | Removes unnecessary attributes in HTML tags | YES |
| insert_dns_prefetch | Injects tags in the HEAD to enable the browser to do DNS prefetching | YES |
| remove_quotes | Removes unnecessary quotes in HTML tags | YES |
| trim_urls | Removes unnecessary prefixes from URLs | YES |
| collapse_whitespace | Removes unnecessary whitespace in HTML | YES |
| remove_comments | Removes HTML comments | YES |
| combine_css | Combines multiple CSS files into one | NO |
| combine_heads | Combines multiple elements into one | NO |
| combine_javascript | Combines multiple JavaScript files into one | NO |
| dedup_inlined_images | Replaces repeated inlined images with JavaScript that loads the data from the first instance of the image | NO |
| defer_javascript | Defers the execution of javascript in the HTML | NO |
| pedantic | Adds default type attributes to script and style tags that are missing them | NO |
| extend_cache | Improves cacheability | NO |
| fallback_rewrite_css_urls | Rewrite URLs in CSS even if CSS is not parseable | NO |
| flatten_css_imports | Flattens @import rules in CSS by replacing the rule with the contents of the imported resource | NO |
| hint_preload_subresources | Inserts link: headers to preload CSS and JavaScript resources | NO |
| inline_google_font_css | Inlines small font-loading CSS from Google Fonts API | NO |
| inline_import_to_link | Inlines style tags comprising only CSS @imports by converting them to an equivalent link | NO |
| inline_javascript | Inlines small external Javascript files | NO |
| inline_preview_images | Delays original images; serves inlined, low-quality placeholder images until originals are loaded | NO |
| insert_ga | Inserts Google Analytics javascript snippet | NO |
| lazyload_images | Loads images when they become visible in the client viewport | NO |
| local_storage_cache | Loads inlined CSS and image resources into HTML5 local storage whence the client fetches them subsequently rather than the server sending them again | NO |
| make_show_ads_async | Converts synchronous Google AdSense tags to asynchronous format | NO |
| make_google_analytics_async | Converts synchronous Google Analytics code to load asynchronously | NO |
| move_css_above_scripts | Moves CSS above scripts | NO |
| move_css_to_head | Moves CSS into the element | NO |
| outline_css | Moves large inline <style> tags into external files for cacheability | NO |
| outline_javascript | Moves large inline <script> tags into external files for cacheability | NO |
| prioritize_critical_css | Instruments the page, inlines its critical CSS at the top, and lazily loads the rest | NO |
| resize_mobile_images | Just like inline_preview_images, but uses smaller placeholder images for mobile browsers | NO |
| resize_rendered_image_dimensions | Resize images to rendered dimensions | NO |
| responsive_images | Serve responsive images using the srcset attribute | NO |
| rewrite_css | Minifies CSS | NO |
| rewrite_images | Rescales, and compresses images; inlines small ones | NO |
| rewrite_javascript | Minifies Javascript | NO |
| rewrite_style_attributes | Rewrite the CSS in style attributes by applying the configured rewrite_css filter to it | NO |
| rewrite_style_attributes_with_url | Rewrite the CSS in style attributes by applying the configured rewrite_css filter to it, but only if the attribute contains the text 'url(' | NO |
| sprite_images | Sprites images | NO |
Configuration
After installing package, you may need to configure some options.
Disable Service
You would probably like to set up the local environment to get a readable output.
//config/laravel-page-speed.php //Set this field to false to disable the laravel page speed service. 'enable' => env('LARAVEL_PAGE_SPEED_ENABLE', true),
Skip routes
You would probably like to configure the package to skip some routes.
//config/laravel-page-speed.php //You can use * as wildcard. 'skip' => [ '*.pdf', //Ignore all routes with final .pdf '*/downloads/*',//Ignore all routes that contain 'downloads' ];
By default this field comes configured with some options, so feel free to configure according to your needs...
Notice: This package skip automatically binary response. See File Downloads.
Testing
$ composer test
Contributing
Please see CONTRIBUTING for details.
Credits
Inspiration
Mod Page Speed (https://www.modpagespeed.com/)
License
The MIT License (MIT). Please see License File for more information.
asyrafhussin/laravel-page-speed 适用场景与选型建议
asyrafhussin/laravel-page-speed 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 201 次下载、GitHub Stars 达 1, 最近一次更新时间为 2018 年 02 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「html」 「minify」 「laravel」 「page speed」 「optmize」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 asyrafhussin/laravel-page-speed 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 asyrafhussin/laravel-page-speed 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 asyrafhussin/laravel-page-speed 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Texy converts plain text in easy to read Texy syntax into structurally valid (X)HTML. It supports adding of images, links, nested lists, tables and has full support for CSS. Texy supports hyphenation of long words (which reflects language rules), clickable emails and URL (emails are obfuscated again
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
Caching and compression for Twig assets (JavaScript and CSS).
CSS & JavaScript minifier for Silverstripe
A package for pack css and javascript files
Modification of rmrevin/yii-2-minify-view lib to allow minification of css & js in a load balanced environment
统计信息
- 总下载量: 201
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-02-08