Registry / http-networking / lws-conditional-get

lws-conditional-get

JSON →
library3.0.0jsnpmunverified

lws-conditional-get is a specialized middleware designed for integration with the `lws` (local-web-server) ecosystem. Its core function is to add robust HTTP Conditional-GET caching capabilities to `lws`-powered web servers, leveraging the well-regarded `koa-conditional-get` library internally. This enables efficient resource delivery by utilizing `If-None-Match` and `If-Modified-Since` HTTP headers, thereby reducing redundant data transfers and improving client-side performance. The package is currently at version 3.0.0 and appears to be actively maintained, with a likely release cadence tied to updates in its upstream dependencies or the `lws` project itself. Its primary value lies in offering a low-configuration solution for implementing standard HTTP caching directly within the `lws` environment, abstracting away the complexities of conditional request handling.

npm install lws-conditional-get
INSTALL
IMPORT
SIG · LWS-CONDITIONAL-GE
L
lws-conditional-get
http-networkingjavascriptv3.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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
musl
node 18226 runs
build_error
glibc
node 18226 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.
fix
If 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.
fix
If 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.
fix
Always 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.
fix
Run `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.
fix
Use a default import for ESM (`import conditionalGet from 'lws-conditional-get'`) or directly require the module for CommonJS (`const conditionalGet = require('lws-conditional-get')`).
Upgrade
Version history
3.0.0latest on npm
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.
Agent activity
3 hits · last 30 days
node
2
Amazon
1
Resources
lws-conditional-get — npm install lws-conditional-get · libregistry