Zid Docs
AppsThemes
Payments
AppsThemes
Payments
Help Center
Slack
  1. Tips & Tricks
  • Getting Started
    • Introduction
    • Theme Development
    • Vitrin Changelog
    • Creating and Managing Theme Presets
    • Legacy Theme Migration
      • Store Settings Mapping
      • Moving to Vitrin Using LLMs
      • Twig to Jinja
      • Breaking Changes
  • Key Concepts
    • Architecture
    • Templates
      • Overview
      • Overridable Templates
      • Legacy Templates
      • Template Replacements
      • Templates Library
        • home.jinja
        • product.jinja
        • cart.jinja
        • category.jinja
        • products.jinja
        • categories.jinja
        • page.jinja
        • blogs.jinja
        • blog.jinja
        • faqs.jinja
        • reviews.jinja
        • questions.jinja
        • shipping_payment.jinja
        • 404_not_found.jinja
    • Settings
      • Schema files
      • Input Settings
      • Media Settings
      • Form Controls Settings
      • Products Settings
      • Additional Settings
      • Conditional Visibility
      • Migrating twig settings schema
    • Localization
      • localization (jinja v. twig)
    • Theme Editor
      • Overview
  • Building with Vitrin
    • Jinja Basics
    • Vitrin's Jinja Extensions
  • Vitrin CLI
    • Introduction
    • CLI Commands
  • Tips & Tricks
    • Performance
  • JS Integration
    • Supporting both Vitrin and Legacy themes
    • Responses & Errors
    • Cart
    • Products
    • Categories
    • Store
    • Account
    • Blogs
    • Options
    • Events
  • Features
    • SDK Popups – Integration Guidelines
    • Custom Styles Guide
    • Gift Card as a Popup
    • Addresses as a Popup
    • Login as a Popup
    • Checkout as a Popup
    • Apple Pay Quick Checkout
    • Region & Language Popup
    • Dynamic Bundle Products
    • Progressive Discounts
    • Customer Wallet & Cashback
    • Add Preorder Support to Your Theme
  • Mobile Apps
    • Scripts
  • API's
    • Authentication
      • Logout
      • Login Status
      • SMS Login
      • Verify SMS Login
      • WhatsApp Login
      • Verify WhatsApp Login
      • Email Login
      • Verify Email Login
      • Register
      • Register Guest
    • Products
      • List Products
      • Search Products
      • Calculate Product Options Price
      • Notify Product Stock Availability
      • Fetch Bundle Offers
      • Fetch Bundle Offers for a Product
      • List My Product Reviews
      • List Product Reviews
      • Create Product Review
      • Update Product Review
      • Delete Product Review
      • List Product Questions
      • Create Product Question
      • Get Product by Slug
      • Get Selection Groups
    • Categories
      • List Categories
    • Checkout
      • Get Cart
      • Remove Cart
      • Duplicate Cart
      • Add Cart Item
      • Empty Cart
      • Update Cart Item
      • Remove Cart Item
      • Upload Cart Input Field
      • Add Gift Card
      • Remove Gift Card
      • Apply Coupon
      • Remove Coupon From Cart
      • Check Coupon Validity
      • Apply Loyalty Points
      • Remove Loyalty Points
      • Preview Rewarded Points
      • List Redemption Methods for Cart
      • Customer’s Loyalty Wallet
      • Customer’s Current Points Balance
    • Account
      • Get Profile
      • Delete Account
      • Update Customer Profile
      • Get Addresses
      • Create an Address
      • Get an Address by ID
      • Update an Existing Address
      • Delete Address
      • Get Orders
      • Get Shareable Wishlist Link
      • Get Wishlist
      • Add Products to Wishlist
      • Remove Product from Wishlist
      • Get Address Form Schema
      • Check Product Purchase Status
    • Storefront
      • Store Scripts
      • Pages
      • Blogs
    • Countries
      • Get Countries
      • Get Cities By Country
  1. Tips & Tricks

Performance

Follow these tips to improve loading times and Core Web Vitals scores.

image_url filter#

Use image_url to generate fast, responsive, modern images without changing your original assets.
📌
Use image_url to serve AVIF/WebP images, control quality, and generate multiple sizes on the fly.

What it does#

The image_url filter is a macro built into the Vitrin theme SDK. It lets you:
1.
Convert images to modern formats (AVIF / WebP) dynamically
2.
Adjust image quality for faster downloads, especially on mobile
3.
Generate different sizes for responsive layouts (srcset, etc.)

Signature#

image_url(path, w=None, h=None, q=None, f=None)
Parameters:
path (required) – URL or path to the original image
w – Output width in pixels
h – Output height in pixels
q – Output quality from 0 to 100
f – Output format. Use 'auto' to let the client’s browser choose the best supported format (recommended)

Basic usage#

{{ image_url(ny_image, w=400, q=85, f='auto') }}
This returns a URL to a 400px-wide, high-quality, auto-formatted image.

Responsive srcset example#

The browser will automatically pick the most appropriate size for the user’s device and viewport.

1
Step 1 – Start simple
Replace hard-coded image URLs with {{ image_url(...) }} in your templates.
2
Step 2 – Tune quality
Use q (e.g. q=70) to balance visual quality and performance, especially for mobile.
3
Step 3 – Add responsiveness
Generate several widths and build a srcset so images stay sharp on all screen sizes.

Preload Critical Assets#

Preloading key images can significantly improve your Core Web Vitals:
First Contentful Paint (FCP) — Preload the store logo so it appears as soon as possible.
Largest Contentful Paint (LCP) — Preload large banners or hero images to speed up main visual rendering.
Add the preload tags in your <head> section:
<link rel="preload" as="image"
      href="{{ image_url(logoUrl, h=175, q=100) }}"
      media="(min-width: 992px)">

{% if logoUrlMobile %}
  <link rel="preload" as="image"
        href="{{ image_url(logoUrlMobile, h=175, q=100) }}"
        media="(max-width: 991px)">
{% else %}
  <link rel="preload" as="image"
        href="{{ image_url(logoUrl, h=175, q=100) }}"
        media="(max-width: 991px)">
{% endif %}
The media attribute specifies the viewport size that triggers the preloading.
In the example above, we preload a different logo for desktop and mobile, with a fallback to the desktop logo if logoUrlMobile is not defined.

Optimize Script Loading#

Use async for scripts that don’t require order.
Use defer for scripts that require order but should not block rendering:

Image Optimization#

Use responsive images with srcset to serve the right size based on device:
Modified at 2026-02-17 07:02:10
Previous
CLI Commands
Next
Supporting both Vitrin and Legacy themes
Built with