Basic ucdn utilities in order to just serve files.

Usage no npm install needed!

<script type="module">
  import ucdnUtils from 'https://cdn.skypack.dev/ucdn-utils';



Build Status Coverage Status

Basic µcdn utilities in order to just serve files pre generated via µcompress.

The only interesting utility to use is likely the serve(path[, cacheTimeout]) one, as the rest is mostly needed for internal purposes in µcdn module or in here.

Please Note

This module assumes all files already have associated headers. If you don't have those headers files, please use ucompress.createHeaders(path) before serving via serve(path[, cacheTimeout]).


The following example will serve every file within any folder in the source directory, automatically optimizing on demand all operations, including the creation of brotli, gzip, or deflate.

import {createServer} from 'http';
import {serve} from 'ucdn-utils';

import umeta from 'umeta';
const {dirName} = umeta(import.meta);

const callback = serve(dirName + '/source', 60000);


The callback works with Express too, and similar modules, where all non existent files in the source folder will be ignored, and anything else will execute regularly.

const {join} = require('path');

const express = require('express');
const {serve} = require('ucdn-utils');

const app = express();
app.use(serve(join(__dirname, 'source')));
app.get('/unknown', (req, res) => {
  res.writeHead(200, {'Content-Type': 'text/plain'});