Performance Optimization#
Performance optimization is a critical aspect of building efficient and user-friendly Miva Merchant stores. Slow-loading pages or unresponsive interactions can negatively impact user experience, search rankings, and conversion rates. This guide outlines best practices, KPIs, and actionable tips for optimizing your Miva Merchant templates and processes.
Key Performance Metrics (KPIs)#
Monitoring and improving these metrics is essential for a performant site
Note
For the most up-to-date Key Performance Indicators (KPIs), including definitions and thresholds for metrics like TTFB, FCP, and LCP, refer to web.dev/metrics.
Name | Code | Definition | Good | Average | Poor |
---|---|---|---|---|---|
Time to First Byte (TTFB) | TTFB | Measures the duration from the user making an HTTP request to the first byte of the page being received. Indicates server responsiveness. | < 800 ms | 800 ms to 1800 ms | >= 1800 ms |
First Contentful Paint (FCP) | FCP | Measures the time when the browser renders the first visible element on the page. | < 1800 ms | 1800 ms to 3000 ms | >= 3000 ms |
Largest Contentful Paint (LCP) | LCP | Indicates when the largest visible content element is fully loaded. | < 2500 ms | 2500 ms to 4000 ms | >= 4000 ms |
First Input Delay (FID) | FID | Measures the time between a user’s first interaction and the browser’s response. | < 100 ms | 100 ms to 300 ms | >= 300 ms |
Cumulative Layout Shift (CLS) | CLS | Quantifies unexpected layout shifts that affect visual stability. | < 0.1 | 0.1 to 0.25 | >= 0.25 |
Best Practices#
Regular Auditing#
- Perform periodic Lighthouse audits to evaluate performance.
- Use pagespeed.web.dev.
- Strive for scores in the 80-100 range but aim to stay above 50 at a minimum.
- Refer to web.dev/fast and Front-End Performance Checklist for actionable improvements.
Efficient Loops#
Loops are powerful but can harm performance if not used carefully. Avoid unnecessary iterations by breaking out of loops when goals are achieved.
Incorrect
<mvt:assign name="l.settings:has_forbidden_items" value="0" />
<mvt:foreach iterator="group" array="basket:groups">
<mvt:item name="customfields" param="Read_Product_ID( l.settings:group:product_id, 'forbidden', l.settings:group:customfield_values:customfields:forbidden )" />
<mvt:if expr="l.settings:group:customfield_values:customfields:forbidden">
<mvt:assign name="l.settings:has_forbidden_items" value="1" />
</mvt:if>
</mvt:foreach>
Correct
<mvt:assign name="l.settings:has_forbidden_items" value="0" />
<mvt:foreach iterator="group" array="basket:groups">
<mvt:item name="customfields" param="Read_Product_ID( l.settings:group:product_id, 'forbidden', l.settings:group:customfield_values:customfields:forbidden )" />
<mvt:if expr="l.settings:group:customfield_values:customfields:forbidden">
<mvt:assign name="l.settings:has_forbidden_items" value="1" />
<mvt:foreachstop />
</mvt:if>
</mvt:foreach>
Efficient Functions#
Prefer cached functions to reduce redundant database lookups and optimize performance.
Incorrect
<mvt:do file="g.Module_Library_DB" name="l.product_loaded" value="Product_Load_Code( l.product_code, l.product )" />
Correct
<mvt:do file="g.Module_Library_DB" name="l.product_loaded" value="Product_Load_Code_Cached( l.product_code, l.product )" />
Avoid Infinite Loops#
Ensure loops terminate correctly to prevent infinite cycles that degrade performance.
Incorrect
<mvt:if expr="g.Empty_Cart">
<mvt:do file="g.Module_Library_DB" name="l.success" value="Runtime_Basket_Empty( g.Basket:basket_id )" />
<mvt:assign name="l.result" value="miva_output_header( 'Location', 'https://' $ encodeentities(g.domain:name) $ s.request_uri )" />
<mvt:exit />
</mvt:if>
<a href="&mvte:urls:BASK:auto_sep;Empty_Cart=1">Empty Cart</a>
Correct
<mvt:if expr="g.Empty_Cart">
<mvt:do file="g.Module_Library_DB" name="l.success" value="Runtime_Basket_Empty( g.Basket:basket_id )" />
<mvt:assign name="l.result" value="miva_output_header( 'Location', encodeentities( l.settings:urls:BASK:auto ) )" />
<mvt:exit />
</mvt:if>
<a href="&mvte:urls:BASK:auto_sep;Empty_Cart=1">Empty Cart</a>
Summary#
Optimizing performance ensures a better user experience, improved search rankings, and reduced server load. By focusing on efficient processes, proper auditing, and adhering to best practices, you can build high-performing Miva Merchant templates.