{"repo":"unjs/serve-placeholder","free":true,"listed":false,"github":"https://github.com/unjs/serve-placeholder","clone":"git clone https://github.com/unjs/serve-placeholder.git","description":"♡ Smart placeholder for missing assets","language":"TypeScript","stars":171,"topics":["connect","express","node","ssr","vue","nuxt","middleware","404"],"license":"MIT","category":"api-integrations-sdks","readme_excerpt":"♡ serve-placeholder Smart placeholder for missing assets Why? 💵 Rendering Errors is costly Serving each 404 page for assets adds extra load to the server and increases crashing chances. This is crucial for setups with server-side-rendering and removes additional SSR loads when assets like robots.txt or favicon.ico don't exist. 👌 Meaningful Responses We can always send a better 404 response than an HTML page by knowing file extensions. For example, we send a fallback transparent 1x1 image for image extensions. 🔍 SEO Friendly Instead of indexing invalid URLs with HTML pages, we properly send 404 and the right content type. Usage Install package: Import: Create and add server middleware between serve-static and router middleware: Additionally, we can have a default placeholder for arbitrary routes which handles known extensions assuming other routes have no extension : Options handlers A mapping from file extensions to the handler. Extensions should start with dot like .js . You can disable any of the handlers by setting the value to null If the value of a handler is set to false , the middleware will be ignored for that extension. statusCode - Default: 404 Sets statusCode for all handled responses. Set to false to disable overriding statusCode. skipUnknown - Default: false Skip middleware when no handler is defined for the current request. Please note that if this option is set to true , then default handler will be disabled! placeholders - Type: Object A mapping from handle","default_branch":null,"files":null,"tree":[],"storefront":"/r/unjs","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/unjs/serve-placeholder/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}