JSPM

asset-extensions

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q26217F
  • License MIT

A list of extensions for web assets.

Package Exports

  • asset-extensions

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (asset-extensions) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

asset-extensions

A list of extensions for web assets.

Installation

npm install asset-extensions

Usage

const assetExtensions = require('asset-extensions');
const fontExtensions = require('asset-extensions/lib/font');
const imageExtensions = require('asset-extensions/lib/image');
const scriptExtensions = require('asset-extensions/lib/script');
const styleExtensions = require('asset-extensions/lib/style');

const isPathAsset = require('asset-extensions/lib/util/isPathAsset');

Example

Connect middleware to set HTTP response headers:

const isPathAsset = require('asset-extensions/util/isPathAsset');
const imageExtensions = require('asset-extensions/image');

module.exports = (req, res, next) => {
  const isAsset = isPathAsset(req.url)
  const isImage = isPathAsset(req.url, imageExtensions)

  if (!isPathAsset(req.url)) {
    res.setHeader('Content-Security-Policy', '...');
  }

  if (isPathAsset(req.url, imageExtensions)) {
    res.setHeader('Cache-Control', '...');
  }

  next();
};