Skip to content
pubscout

shelf_static

1.2.0, released 5 weeks ago by tools.dart.dev

Serve static files over HTTP with the shelf package

Rock solid
$ flutter pub add shelf_static
Source repository

What it does

shelf_static provides a Handler that serves files from a directory, supporting range requests, ETag and Cache‑Control headers. It replaces blocking IO with async calls for better concurrency.

AI-written summary of version 1.2.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • Building a simple web server or API that needs to serve static assets
  • Prototyping or testing a shelf‑based application
  • Serving documentation or public files in a Dart backend

Skip it when

  • You need a highly optimized CDN‑style static file server with advanced caching or compression
  • Your project already uses another static file server that integrates with your framework

Strengths

  • Non‑blocking async file access
  • Built‑in support for HTTP range, ETag, and Cache‑Control
  • Easy integration with shelf middleware
  • Responsive directory listing UI

Weaknesses

  • Limited to the shelf ecosystem
  • No built‑in HTTPS support (handled by shelf_io or other server)
  • No advanced caching or compression features

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
5

Add shelf_static to pubspec, import, create a handler with createStaticHandler, and serve with shelf_io. No extra permissions or build_runner needed.

import 'package:shelf/shelf_io.dart' as io;
import 'package:shelf_static/shelf_static.dart';

void main() {
  var handler = createStaticHandler('example/files', defaultDocument: 'index.html');
  io.serve(handler, 'localhost', 8080);
}

Alternatives

Packages that do the same job and could replace shelf_static.

  • relic

    Lightweight web server framework inspired by Shelf, with typed APIs and a high‑performance native Zig adapter.

  • ftp_server

    Standards-compliant FTP and FTPS server implementation in Dart.

Works with

Packages commonly used together with shelf_static: ones it builds on, ones built on it, and its own family.