Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
conditionalGet
✓ import conditionalGet from 'lws-conditional-get'
✗ import { conditionalGet } from 'lws-conditional-get'
The package exports a default function, not a named export. ESM usage.
conditionalGet
✓ const conditionalGet = require('lws-conditional-get')
CommonJS usage. The `lws` ecosystem traditionally used CommonJS, but newer Node.js versions support ESM.
lws-conditional-get (as part of lws stack)
✓ const lws = require('lws');
lws.create({ stack: [ require('lws-conditional-get')() ] });
Typically, the middleware function is instantiated and passed directly to the `lws` stack configuration.
This quickstart demonstrates how to set up an `lws` server with `lws-conditional-get` middleware to enable HTTP Conditional-GET caching for static files.
import lws from 'lws';
import conditionalGet from 'lws-conditional-get';
import fs from 'fs';
import path from 'path';
// Ensure a 'public' directory exists for static files
const publicDir = path.join(process.cwd(), 'public');
if (!fs.existsSync(publicDir)) {
fs.mkdirSync(publicDir);
}
// Create some dummy files to serve
fs.writeFileSync(path.join(publicDir, 'index.html'), '<h1>Hello from conditional-get!</h1>\n');
fs.writeFileSync(path.join(publicDir, 'style.css'), 'body { font-family: sans-serif; }\n');
const server = lws.create({
port: 8000,
stack: [
conditionalGet(), // Include the conditional-get middleware
lws.static({ directory: publicDir }) // Serve static files from 'public'
]
});
server.listen(8000, () => {
console.log('lws-conditional-get demo server running on http://localhost:8000');
console.log('Access http://localhost:8000/index.html in your browser.');
console.log('Subsequent requests (e.g., refresh) should show ' + '"304 Not Modified" for static assets in network inspector.');
});
// To run this example:
// 1. Create a file named `server.js`
// 2. `npm install lws lws-conditional-get`
// 3. `node server.js`
Debug
Known issues
gotchaWhile `lws-conditional-get` is enabled by default if included in the `lws` stack, its behavior can be explicitly disabled via the `--no-conditional-get` command-line flag or equivalent configuration, which developers might overlook if expecting direct control.fixIf unexpected caching occurs, ensure the `--no-conditional-get` flag is not present. For explicit control, you might need to manage the middleware's inclusion in the `lws` stack programmatically.
affects: >=1.0.0
gotcha`lws-conditional-get` relies on `koa-conditional-get`. Issues or breaking changes in specific versions of `koa-conditional-get` could indirectly affect the behavior or stability of this middleware. Always check for upstream dependency release notes.fixIf experiencing unexpected behavior, consult the release notes and issue trackers for both `lws-conditional-get` and `koa-conditional-get` for any known incompatibilities or required updates.
affects: >=1.0.0
breakingUpgrading `lws` itself to a new major version might introduce changes to its middleware API, potentially requiring updates to how `lws-conditional-get` is integrated or configured, even if `lws-conditional-get` itself hasn't had a major release.fixAlways review the release notes for major `lws` versions and update your `lws` configuration and middleware instantiation patterns accordingly.
affects: >=1.0.0 (applies to `lws` major version upgrades)
Errors
Common errors & fixes
Error: Cannot find module 'lws' or 'lws-conditional-get'
The required `lws` or `lws-conditional-get` package has not been installed, or the Node.js module resolution path is incorrect.
fixRun `npm install lws lws-conditional-get` in your project directory to ensure all dependencies are present.
TypeError: conditionalGet is not a function
This error typically occurs if you're attempting to import `lws-conditional-get` using named imports (e.g., `import { conditionalGet } from 'lws-conditional-get'`) when the package exports a default function.
fixUse a default import for ESM (`import conditionalGet from 'lws-conditional-get'`) or directly require the module for CommonJS (`const conditionalGet = require('lws-conditional-get')`). Audit
Dependencies
lwsrequiredCore server framework this middleware integrates with. It's a de-facto peer dependency for any `lws` middleware.
koa-conditional-getrequiredUnderlying library providing the core conditional-get logic for the middleware.