Delaying Inline Scripts
To delay the execution of inline scripts and improve website performance, you can follow these methods:
Method 1: Using RapidLoad
- Identify the inline script: Determine the specific inline script that you want to delay.
- Access RapidLoad settings: In RapidLoad, locate the option for "Delay Javascripts to Load on User Interaction."
- Enter a part of the inline script as a string: To delay the desired inline script, enter a part of the script as a string in the designated text box. It's important to provide a unique portion of the script that can be identified.
Example:<script type="text/javascript" id="">!function(d,g,e){d.TiktokAnalyticsObject=e;var a=d[e]=d[e]||[];a.methods="page track identify instances debug on off once ready alias group enableCookie disableCookie".split(" ");a.setAndDefer=function(b,c){b[c]=function(){b.push([c].concat(Array.prototype.slice.call(arguments,0)))}};for(d=0;d<a.methods.length;d++)a.setAndDefer(a,a.methods[d]);a.instance=function(b){b=a._i[b]||[];for(var c=0;c<a.methods.length;c++)a.setAndDefer(b,a.methods[c]);return b};a.load=function(b,c){var f="https://analytics.tiktok.com/i18n/pixel/events.js"; a._i=a._i||{};a._i[b]=[];a._i[b]._u=f;a._t=a._t||{};a._t[b]=+new Date;a._o=a._o||{};a._o[b]=c||{};c=document.createElement("script");c.type="text/javascript";c.async=!0;c.src=f+"?sdkid\x3d"+b+"\x26lib\x3d"+e;b=document.getElementsByTagName("script")[0];b.parentNode.insertBefore(c,b)};a.load("xxxxxxxxx");a.page()}(window,document,"ttq");</script>
You can enter the URLhttps://analytics.tiktok.com/i18n/pixel/events.js
as a string in the RapidLoad text box. - Save the changes: Save the changes to apply the delay to the specified inline script.
Method 2: Manually adding the "data-rapidload-delayed" tag
- Identify the inline script: Determine the specific inline script that you want to delay.
- Locate the inline script tag: Find the opening tag of the inline script, typically starting with
<script>
. - Add the "data-rapidload-delayed" attribute: Insert the attribute
data-rapidload-delayed
within the opening tag of the inline script. This attribute will mark the script to be excluded from immediate execution.
Example:<script data-rapidload-delayed> // Your inline script code here </script>
Ensure that thedata-rapidload-delayed
attribute is added to the script tag you want to delay. - Save the changes: Save the changes to your HTML document.
By utilizing RapidLoad or manually adding the data-rapidload-delayed
attribute, you can effectively delay inline scripts, resulting in improved page load times and enhanced website performance.
Note: When using RapidLoad, it's essential to identify a unique part of the inline script code to avoid unintended delays or conflicts with other scripts.