Static File Handling
Learning Focus
By the end of this lesson you will understand how OpenLiteSpeed serves static files, why direct serving is faster than routing through PHP, and how to configure it.
Why Direct Static Serving Matters
When OpenLiteSpeed serves a static file (image, CSS, JS), it reads the file from disk and sends it directly — no PHP execution, no application framework overhead. This is orders of magnitude faster than routing the same file through a PHP handler.
What Should Be Served Statically
| File Type | Examples | Should Be Static? |
|---|---|---|
| Stylesheets | .css | ✅ Yes |
| JavaScript | .js | ✅ Yes |
| Images | .png, .jpg, .webp, .svg | ✅ Yes |
| Fonts | .woff2, .ttf | ✅ Yes |
| Documents | .pdf, .zip | ✅ Yes |
| PHP scripts | .php | ❌ No — needs handler |
How OpenLiteSpeed Decides
OpenLiteSpeed checks the file extension and context configuration:
- If the extension maps to a script handler (e.g.,
.php→ lsphp), it runs the handler - If no handler matches, it serves the file directly from disk
- Context rules can override this behavior for specific paths
Configuration Tips
- Avoid routing images, stylesheets, or downloads through PHP unless your application requires it
- Use static contexts for dedicated asset directories
- Ensure static file directories have correct permissions (
755for dirs,644for files)
# Verify a static file is served without PHP involvement
curl -sI https://example.com/style.css | grep -iE "content-type|x-litespeed"
# Should show content-type: text/css with no PHP headers
Key Takeaways
- Direct static serving is the fastest delivery method — no application overhead.
- Ensure common assets (CSS, JS, images) are not accidentally routed through PHP.
- Use contexts to organize and optimize static file delivery.
What's Next
- Continue to File Cache to learn about in-memory file caching.