Performance β
A fast storefront isn't just a nice-to-have β it drives conversions, improves SEO, reduces bounce, and creates a smoother experience for merchants and customers alike.
This guide provides practical tips for building performant Bagisto Visual themes and sections, with a focus on the live storefront.
π§© Editor preview performance is covered separately: Integrating with the Editor
1. Keep Your Markup Lean β
- Donβt over-nest elements. Avoid structures like
<div><div><div>...</div></div></div>
- Use semantic elements (
<section>
,<h2>
,<ul>
) to reduce overhead and improve clarity - Only render content when needed:
blade
@if ($section->settings->heading)
<h2 class="text-primary">{{ $section->settings->heading }}</h2>
@endif
- Use
@empty
,@unless
, or??
to prevent rendering empty elements
2. Load Images Responsibly β
- Add
loading="lazy"
to all images that arenβt visible on first render - Always define
width
andheight
to prevent layout shifts - Use compressed and appropriately sized images
- For responsive assets, use
srcset
andsizes
blade
<img
src="{{ $section->settings->image }}"
alt="{{ $section->settings->alt }}"
width="800"
height="400"
loading="lazy"
/>
3. Defer Section-Specific JavaScript β
- Use
@push('scripts')
or similar to load JS only when the section is used - Avoid global scripts for features like carousels or modals that are section-scoped
- Add
type="module"
anddefer
to reduce blocking
blade
@push('scripts')
<script type="module" defer>
// Behavior tied to this section
</script>
@endpush
4. Avoid Expensive Blade Logic β
- Avoid database queries,
json_decode
, or filtering inside Blade - Do data prep in the section class (controller layer)
- Use Laravel collections sparingly inside views β prefer
collect($data)->filter()
in PHP
β Good:
php
return [
'products' => Product::limit(4)->get(),
];
π« Avoid:
blade
@foreach (Product::all() as $product)
5. Prioritize Mobile Responsiveness β
- Mobile users are the majority β test every section at 320px, 375px, and 768px
- Avoid fixed-width images and layouts
- Use readable text sizes and adequate spacing
- Ensure buttons are at least 44Γ44px tappable
6. Test Like a Real User β
Use these tools to simulate real-world performance:
- PageSpeed Insights
- WebPageTest
- Lighthouse (Chrome DevTools β Audits tab)
Simulate:
- Slow 3G
- Low CPU
- Cold cache
And fix:
- Layout shifts
- Image pop-ins
- Unused code
Summary β
- Write efficient markup and only render what's necessary
- Lazy-load images with proper dimensions
- Keep JS scoped and defer it when possible
- Avoid expensive logic in Blade β prep data in PHP
- Prioritize mobile users and test your work with real tools
Fast themes feel better, rank better, and convert better.