定制 braesident/js_assets 二次开发

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

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

braesident/js_assets

最新稳定版本:1.0.3

Composer 安装命令:

composer require braesident/js_assets

包简介

Load different javascript assets

README 文档

README

JsAsset is a small utility class that discovers JavaScript files, renders them as <script> tags, or returns their content directly (optionally minified).

The class works with:

  • local files in assets/*.js
  • optional JS files from Composer dependencies (vendor/<vendor>/<package>/*.js)

Purpose

Typical use cases:

  • automatically discover available JS assets
  • generate script tags for templates from one central place
  • serve JS content through your own endpoint (with optional minification)
  • use file-based cache and manifest invalidation when source files change

Installation

composer require braesident/js_assets

Available API

  • JsAsset::getAssets(): array
  • JsAsset::getScriptTagArray(string $path = '', string ...$matches): array
  • JsAsset::getScriptTags(string $path = '', string ...$matches): string
  • JsAsset::getAsset(string $path, bool $minify = false): string

Snippets

1) Render script tags for all assets

<?php

use braesident\JsAsset\JsAsset;

echo JsAsset::getScriptTags('/asset');

Example output:

<script type="text/javascript" src="/asset/app.js"></script>
<script type="text/javascript" src="/asset/dropdown.js"></script>

2) Render only specific assets

<?php

use braesident\JsAsset\JsAsset;

$tags = JsAsset::getScriptTagArray('/asset', 'app', 'dropdown');

foreach ($tags as $tag) {
  echo $tag.PHP_EOL;
}

3) Return raw asset content (for a controller/route)

<?php

use braesident\JsAsset\JsAsset;

header('Content-Type: application/javascript; charset=UTF-8');
echo JsAsset::getAsset('/asset/dropdown.js');

4) Return minified content with cache

<?php

use braesident\JsAsset\JsAsset;

header('Content-Type: application/javascript; charset=UTF-8');
echo JsAsset::getAsset('/asset/dropdown.js', true);

When true is passed, matthiasmullie/minify is used. Generated files are written to:

  • cache/ (non-minified)
  • cache/mini/ (minified)
  • cache/manifest.json (path, mtime, hash per asset)

If a source file changes, cache entries are refreshed automatically.

Notes About Asset Names

  • In getAsset(), only the asset file name is relevant; prefixes like /asset/ and .js are tolerated.
  • If local and external assets share the same base name, an external key can appear as <vendor>.<package>.<filename>.

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: proprietary
  • 更新时间: 2026-03-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固