Async Script Loading
Consent Pro supports loading scripts asynchronously to ensure your website performance is not impacted by consent management.
Overview
By default, Consent Pro blocks third-party scripts until user consent is granted. When consent is provided, blocked scripts are loaded asynchronously to avoid blocking the main thread and degrading page performance.
How It Works
- Script Detection — Consent Pro scans your page for third-party scripts and categorizes them based on your configuration
- Script Blocking — Scripts that require consent are prevented from loading until the user grants permission
- Async Loading — Once consent is granted, scripts are loaded asynchronously in the correct order
Using the async Attribute
Add the async attribute to your Consent Pro script tag to load it without blocking page rendering:
diff
<script
src="https://api.consentpro.com/v2/cdn/runtime/your-project-id.js"
type="text/javascript"
finsweet="consentpro"
siteid="your-project-id"
+ async
></script>This ensures:
- The page continues rendering while Consent Pro loads
- Consent Pro initializes as soon as it's ready
- Third-party scripts are managed immediately after initialization
Callback Queue Pattern
Since the script loads asynchronously, use the callback queue pattern to ensure your code runs after Consent Pro is ready:
javascript
window.FinsweetConsentPro = window.FinsweetConsentPro || [];
window.FinsweetConsentPro.push([
'consent',
(consent) => {
// Your code here — runs after Consent Pro initializes
},
]);Best Practices
- Always use the non
asyncattribute on the Consent Pro script tag for proper compliance management - Use the callback queue pattern instead of relying on script load order
- Place the Consent Pro script tag as early as possible in the
<head>for faster initialization - Avoid using
defer— useasyncto ensure consent is evaluated as early as possible