rabbit-loader/php-sdk

RabbitLoader的PHP SDK,用于优化网站性能

v1.0.8 2024-08-13 06:24 UTC

This package is auto-updated.

Last update: 2024-09-13 06:30:07 UTC


README

RabbitLoader PHP SDK可以用于加速使用核心PHP或框架构建的任何网站。

亮点

  • 🚀 提升自定义开发网站所有页面的PageSpeed Insights得分
  • 🏗️ 通过转换为NextGen AVIF和WebP格式自动减少图像大小约40%
  • ➰ 懒加载页脚下的图像和YouTube视频
  • 📱 通过生成关键CSS自动减少CSS大小98%,以实现网页的最快渲染
  • ✨ 提高所有核心Web Vitals指标(降低FCP、FID和CLS)
  • ⚡️ 由于页面速度优化和健康的核心Web Vitals指标,Google搜索排名更高且转化率更好
  • 🌐 通过内置的CDN缓存和提供静态资源(CSS/JS/图像)
  • ♾️ 静态资源的HTTP/3请求和响应多路复用
  • 🗜️ 使用Brotli压缩进行静态资源的传输和加载

安装

composer require rabbit-loader/php-sdk

示例

示例使用,假设index.php是处理网站所有流量的文件。

公共页面示例

#load vendor/autoload.php

#integrate RabbitLoader
$licenseKey = 'YOUR_LICENSE_KEY'; //get your license key from environment variable
$storageDir = '/cache-disk/rabbitloader'; //storage location where cached files will be stored
$rlSDK = new RabbitLoader\SDK\RabbitLoader($licenseKey, $storageDir);
$rlSDK->process();

#remaining code of the website goes after this ...
echo "<h1>Hello World!</h1>"

管理员页面示例

当从管理员面板修改内容时,可以调用此功能以使缓存失效。

#admin.php

$urlModified = 'https://mywebsite.com/modified-page-slug/';
$rlSDK->onContentChange($urlModified);

#if home page needs to be purged too, then-
$rlSDK->onContentChange('https://mywebsite.com/');

跳过某些页面进行缓存和优化

//skip caching if path starts with admin
$rlSDK->skipForPaths(['/admin*']);

//skip caching if a cookie is found with name cookie1 
$rlSDK->skipForCookies(['cookie1']);

//all the above options should come before the process() call
$rlSDK->process();

更多示例和许可证密钥

运行SDK需要许可证密钥。本指南提供了更多代码示例,并解释了如何获取许可证密钥

支持

在此处联系RabbitLoader团队.