承接 mathiasreker/php-script-cache 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

mathiasreker/php-script-cache

最新稳定版本:1.1.0

Composer 安装命令:

composer require mathiasreker/php-script-cache

包简介

php-script-cache is a PHP library for caching external scripts locally.

README 文档

README

Packagist Version Packagist Downloads CI status Contributors Forks Stargazers Issues MIT License

php-script-cache is a PHP library for caching external scripts locally.

✅ Cache ✅ Bundle ✅ Minify

Versions & Dependencies

Version PHP Documentation
^1.0 ^7.4 current

Requirements

  • PHP >= 7.4
  • php-extension ext-json

Installation

Run:

composer require mathiasreker/php-script-cache

Examples

Set up a cronjob to build the assets.

<?php

use MathiasReker\PhpScriptCache\ScriptCache;

require __DIR__ . '/vendor/autoload.php';

(new ScriptCache())
    ->setPath(__DIR__ . '/assets/js')
    ->doMinify()
    ->add([
        'src' => [
            'https://example1.com/script.js',
            'https://example2.com/script.js'
        ], // multiple scripts will get bundled
    ])
    ->add([
        'src' => ['https://example3.com/script.js'],
    ])
    ->build();

Place this code where you want to output the script tags. You can add attributes to the scripts.

<?php

use MathiasReker\PhpScriptCache\ScriptCache;

require __DIR__ . '/vendor/autoload.php';

$result = (new ScriptCache())
    ->setPath(__DIR__ . '/assets/js')
    ->add([
        'src' => [
            'https://example1.com/script.js',
            'https://example2.com/script.js'
        ],
    ])
    ->add([
        'src' => ['https://example3.com/script.js'],
        'id' => 'test',
        'defer' => '',
    ])
    ->fetch();

 // Result: <script src="/assets/js/c5a80e42.js?v=ec25a610"></script><script src="/assets/js/c5a80e42.js?v=539e4fd1" id="test" defer></script>

Documentation

Instantiate the object.

$result = new ScriptCache();
$result->setPath(__DIR__ . '/assets/js');

setPath sets the path of the output folder for built files.

$result->doMinify();

doMinify minifies the content.

$result->add(['src' => ['https://example.com/script.js']]);

add sets the attributes of the script. The src can be an array of several scripts. All the scripts in the collection will get bundled. You can use any attributes. You do not need to set attributes when you build the cache.

$result->build();

build builds the assets.

$result->fetch();

fetch returns a string of the script tags.

Roadmap

See the open issues for a complete list of proposed features (and known issues).

Contributing

If you have a suggestion to improve this, please fork the repo and create a pull request. You can also open an issue with the tag "enhancement". Finally, don't forget to give the project a star! Thanks again!

Docker

If you are using docker, you can use the following command to get started:

docker-compose up -d

Next, access the container:

docker exec -it php-script-cache bash

Tools

PHP Coding Standards Fixer:

composer cs-fix

PHP Coding Standards Checker:

composer cs-check

PHP Stan:

composer phpstan

Unit tests:

composer test

License

It is distributed under the MIT License. See LICENSE for more information.

统计信息

  • 总下载量: 3
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固