apie / javascript-cdn
Composer package of the apie library: javascript cdn
Requires
- php: >=8.4
- apie/common: dev-main
- apie/common-value-objects: dev-main
- apie/core: dev-main
- nyholm/psr7: ^1.8.2
- psr/cache: ^3.0
- psr/http-message: ^2.0
- symfony/http-client: ^7.2|^8.0
Requires (Dev)
- apie/fixtures: dev-main
- phpspec/prophecy-phpunit: ^2.5
- phpunit/phpunit: ^11.5.2
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-12-02 15:39:52 UTC
README
javascript-cdn
This package is part of the Apie library. The code is maintained in a monorepo, so PR's need to be sent to the monorepo
Documentation
This PHP package provides a same-origin proxy for JavaScript packages served by jsDelivr. It registers a global GET /npm/{path} route and proxies valid npm package paths to https://cdn.jsdelivr.net/npm/.
For example, /npm/@ionic/core@7/dist/ionic/ionic.esm.js proxies the corresponding jsDelivr asset. The package path, version, and file path are validated; the upstream host is fixed to jsDelivr.
Successful responses for versioned package paths are cached for 2 years. Paths using the latest version tag are cached for 10 minutes. Redirects from the CDN are cached the same way and rewritten to the same-origin /npm/ route (redirects to other hosts return 502). Other error responses are not cached. Versioned responses are sent with Cache-Control: public, max-age=63072000, immutable so browsers never revalidate them.
Fake packages
By default, fake packages are read from the package's apie-cdn/ directory. To use a different directory, pass it as the third constructor argument to JavascriptCdnProxy. Files under that directory override jsDelivr files using the same path structure. For example:
fake-packages/
└── apie-stacktrace/
└── 0.1.6/
└── dist/
└── apie-stacktrace/
└── apie-stacktrace.esm.js
The file above is returned for /npm/apie-stacktrace@0.1.6/dist/apie-stacktrace/apie-stacktrace.esm.js; requests without a matching local file are proxied to jsDelivr.
This package is PHP-only and does not change the CDN URLs currently emitted by apie/html-builders or the layout packages.