{"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.","language":"javascript","status":"active","last_verified":"Thu Apr 23","install":{"commands":["npm install lws-conditional-get"],"cli":null},"imports":["import conditionalGet from 'lws-conditional-get'","const conditionalGet = require('lws-conditional-get')","const lws = require('lws');\nlws.create({ stack: [ require('lws-conditional-get')() ] });"],"auth":{"required":false,"env_vars":[]},"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}