The Dynamic Yield script delivers personalized experiences to your site visitors. We are constantly working on reducing the effect the script has on your site's loading time. Here's a list of actions you can take to reduce loading time and flicker even further:
Add Preconnect and Prefetch Tags
Since the Dynamic Yield scripts are served from a different hostname than your website, the browser needs to resolve the DNS. Place a dns-prefetch tag before the script to reduce the DNS resolution time.
Preconnect tags allow the browser to setup early connections before an HTTP request is actually sent to the server. This eliminates roundtrip latency and saves time for users. Some browsers (e.g. Explorer, Safari iOS) do not support preconnect tags and ignores it.
<link rel="preconnect" href="//cdn.dynamicyield.com">
<link rel="preconnect" href="//st.dynamicyield.com">
<link rel="preconnect" href="//rcom.dynamicyield.com">
<link rel="dns-prefetch" href="//cdn.dynamicyield.com">
<link rel="dns-prefetch" href="//st.dynamicyield.com">
<link rel="dns-prefetch" href="//rcom.dynamicyield.com">
<script type="text/javascript" src="//cdn.dynamicyield.com/api/[YOUR SITE ID]/api_dynamic.js"></script>
<script type="text/javascript" src="//cdn.dynamicyield.com/api/[YOUR SITE ID]/api_static.js"></script>
The prefetch code has been added to the "get code" in the platform at the beginning of 2019, and the preconnect code has been added in November 2019. If you implemented the script before that, chances are that you are not using this method.
Note: If you're using Dynamic Yield's EU data center (i.e. your admin address is adm.dynamicyield.eu), make sure you also replace the href to ".eu" in the preconnect and dns-prefetch tags.
Exclude jQuery from the Dynamic Yield Script
In the past Dynamic Yield script included a jQuery library ($dy) as part of the script. This has a significant impact on the script size.
Since Q2 2019, the $dy library was removed from the script. Since sometimes customers used this jQuery library in variations, it was only removed from sites (also known as Sections) that were created after Q1 2019.
If you created your site before in Q1 2019 or earlier, and you do not use $dy, please contact your customer success manager to exclude this library from your script.
Archive Campaigns You Don't Need
All active variations in all active experiences in all active campaigns are part of the Dynamic Yield script. Do some cleaning every now and then:
- Pause losing variations in A/B tests if the test reached significant results (best practice regardless of script size). If the control won, pause experience or archive the campaign. Locate A/B tests with conclusive results easily in the dashboard.
- Archive campaigns that are targeted to audiences, pages and selectors that do not exist anymore. Use the "Impressions (Past 7 days)" column in the Site Personalization campaign list to identify campaigns that are no longer being served.
- Archive A/A tests that have ended.
Note: Experiences that are targeted to the past are automatically excluded from the script.
Lazy Load Campaigns
You can enable Dynamic Content and Recommendations campaigns that are "below the fold" to load directly from Dynamic Yield servers, instead of your servers. While this improves your overall site loading speed, it increases the time it takes to load any campaigns that are using this option by 200-500ms.
The option is only enabled by request to your Customer Success Manager, and once enabled you can select whether to enable or disable it for each campaign. Once enabled, each campaign will have an option called Optimize Site Loading Time in the advanced settings.
Use Templates When Needed
If you have an experience with 2 variations that are connected to the same template - the code of the template is added once to the Dynamic Yield script, and variations only include the variables values. If variations will not be connected to the template, the entire code of both variations is be included in the Dynamic Yield script. More code means more delays, so we recommend using templates whenever possible. Learn more about Templates.
Minify Your Variation and Template Code
Minifying the code of the templates and variations can reduce script size significantly. There are various tools online to minify your code (e.g. minifier.org).
Index Products to Improve Recommendation Performance
Larger feeds may experience slower recommendation serving times, although there are many other factors as well such as the amount and type of recommendation rules. If you are concerned or have experienced slow recommendation serving times, we recommend:
- Indexing products using group_id.
- Setting is/is not rules instead of contains/do not contain rules when setting up recommendation rules.
Advanced: Leverage Your Own CDN
Dynamic Yield uses a world leading CDN provider to load its scripts. It is super-fast, and our caching policy is optimized. However, if you experience slowness, it's worth checking the possibility of using your own CDN to load Dynamic Yield’s scripts and host all images that are uploaded to the Dynamic Yield variations. Learn more about CDN integration.
Advanced: Writing to Local Storage
By default, Dynamic Yield stores data into cookies. If you are using a single protocol or single domain site, you can write to the local storage instead of the cookie storage. In order to support this DY.noCookies = true should be placed in the page context as seen in the example below.
<script type="text/javascript">
window.DY = window.DY || {}; DY.recommendationContext = { type: "HOMEPAGE"}; DY.noCookies = true;
</script>
Note: In case no data is found in the local storage, Dynamic Yield will continue reading cookie data. Moreover, In cases where the browser does not support local storage (for example, incognito mode on Safari), Dynamic Yield will continue to write data to the cookie.
Frequently Asked Questions
Google PageSpeed Insights Tool flagged Dynamic Yield's cache policy, what should I do?
Nothing. The Dynamic Yield scripts are downloaded on the visitor’s first pageview on the site (causing a minor delay), but the scripts are loaded from the visitor’s browser’s on the next pageviews. Google does not consider this alarming and it is using the same technique for Google Analytics. It’s important to note that:
- Google PageSpeed Insights score does not reflect SEO ranking
- The score does not affect the Google’s Search crawler
- Google PageSpeed Insights does not measure actual speed, but rather analyzes content and grades webpages according to tagging best practices
- We recommend analyzing your page performance with additional tools (e.g. Pingdom, Test and GTmetrix).
Can I use Dynamic Yield without the client script?
Yes. In 2019, Dynamic Yield launched its server-side API. This allows you to leverage Dynamic Yield core capabilities (behavioral targeting, testing and recommendations) through the server-side. It means there is no flicker and you have full control of the loading time. However, it requires more effort from your developers (e.g. building the variations in your CMS). Learn more about Dynamic Yield's personalization API.