{"id":17786,"library":"lws-conditional-get","title":"lws-conditional-get middleware","description":"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.","status":"active","version":"3.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/lwsjs/conditional-get","tags":["javascript","lws","lws-middleware"],"install":[{"cmd":"npm install lws-conditional-get","lang":"bash","label":"npm"},{"cmd":"yarn add lws-conditional-get","lang":"bash","label":"yarn"},{"cmd":"pnpm add lws-conditional-get","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core server framework this middleware integrates with. It's a de-facto peer dependency for any `lws` middleware.","package":"lws","optional":false},{"reason":"Underlying library providing the core conditional-get logic for the middleware.","package":"koa-conditional-get","optional":false}],"imports":[{"note":"The package exports a default function, not a named export. ESM usage.","wrong":"import { conditionalGet } from 'lws-conditional-get'","symbol":"conditionalGet","correct":"import conditionalGet from 'lws-conditional-get'"},{"note":"CommonJS usage. The `lws` ecosystem traditionally used CommonJS, but newer Node.js versions support ESM.","symbol":"conditionalGet","correct":"const conditionalGet = require('lws-conditional-get')"},{"note":"Typically, the middleware function is instantiated and passed directly to the `lws` stack configuration.","symbol":"lws-conditional-get (as part of lws stack)","correct":"const lws = require('lws');\nlws.create({ stack: [ require('lws-conditional-get')() ] });"}],"quickstart":{"code":"import lws from 'lws';\nimport conditionalGet from 'lws-conditional-get';\nimport fs from 'fs';\nimport path from 'path';\n\n// Ensure a 'public' directory exists for static files\nconst publicDir = path.join(process.cwd(), 'public');\nif (!fs.existsSync(publicDir)) {\n  fs.mkdirSync(publicDir);\n}\n// Create some dummy files to serve\nfs.writeFileSync(path.join(publicDir, 'index.html'), '<h1>Hello from conditional-get!</h1>\\n');\nfs.writeFileSync(path.join(publicDir, 'style.css'), 'body { font-family: sans-serif; }\\n');\n\nconst server = lws.create({\n  port: 8000,\n  stack: [\n    conditionalGet(), // Include the conditional-get middleware\n    lws.static({ directory: publicDir }) // Serve static files from 'public'\n  ]\n});\n\nserver.listen(8000, () => {\n  console.log('lws-conditional-get demo server running on http://localhost:8000');\n  console.log('Access http://localhost:8000/index.html in your browser.');\n  console.log('Subsequent requests (e.g., refresh) should show ' + '\"304 Not Modified\" for static assets in network inspector.');\n});\n\n// To run this example:\n// 1. Create a file named `server.js`\n// 2. `npm install lws lws-conditional-get`\n// 3. `node server.js`","lang":"javascript","description":"This quickstart demonstrates how to set up an `lws` server with `lws-conditional-get` middleware to enable HTTP Conditional-GET caching for static files."},"warnings":[{"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.","message":"While `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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"`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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always review the release notes for major `lws` versions and update your `lws` configuration and middleware instantiation patterns accordingly.","message":"Upgrading `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.","severity":"breaking","affected_versions":">=1.0.0 (applies to `lws` major version upgrades)"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"fix":"Run `npm install lws lws-conditional-get` in your project directory to ensure all dependencies are present.","cause":"The required `lws` or `lws-conditional-get` package has not been installed, or the Node.js module resolution path is incorrect.","error":"Error: Cannot find module 'lws' or 'lws-conditional-get'"},{"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')`).","cause":"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.","error":"TypeError: conditionalGet is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}