0
0
Laravelframework~8 mins

Public disk and symbolic links in Laravel - Performance & Optimization

Choose your learning style9 modes available
Performance: Public disk and symbolic links
MEDIUM IMPACT
This concept affects page load speed by controlling how static files are served and how quickly the browser can access public assets.
Serving user-uploaded files efficiently in a Laravel app
Laravel
Create a symbolic link from public/storage to storage/app/public using 'php artisan storage:link'.
This avoids file duplication by linking directly to storage, enabling faster file access.
📈 Performance GainReduces disk usage and speeds up asset delivery, improving LCP.
Serving user-uploaded files efficiently in a Laravel app
Laravel
Copy user files from storage/app/public to public/ manually or on every request.
This duplicates files and causes unnecessary disk usage and slower file access.
📉 Performance CostAdds extra disk I/O and delays page load due to file copying.
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Manual file copying to public folderN/AN/AIncreased due to slower asset load[X] Bad
Symbolic link from public/storage to storage/app/publicN/AN/AMinimal, fast asset load[OK] Good
Rendering Pipeline
When a browser requests a public asset, the web server resolves the symbolic link to the actual storage location, serving the file without extra copying.
Network Request
File System Access
Browser Rendering
⚠️ BottleneckFile System Access when copying files instead of linking
Core Web Vital Affected
LCP
This concept affects page load speed by controlling how static files are served and how quickly the browser can access public assets.
Optimization Tips
1Use 'php artisan storage:link' to create symbolic links instead of copying files.
2Avoid duplicating files to reduce disk usage and speed up asset delivery.
3Fast access to public disk files improves Largest Contentful Paint (LCP).
Performance Quiz - 3 Questions
Test your performance knowledge
What is the main performance benefit of using a symbolic link for Laravel's public disk?
AAvoids duplicating files and speeds up asset delivery
BIncreases security by hiding files
CAutomatically compresses files for faster loading
DReduces server CPU usage by caching files
DevTools: Network
How to check: Open DevTools, go to Network tab, reload the page, and check the loading time and size of assets served from storage.
What to look for: Look for fast response times and no extra delays caused by file copying or missing files.