Blocking Page Reloads | DataGrail Documentation

On this page

By default, DataGrail Consent reloads the page when a visitor updates their consent preferences. This ensures that scripts blocked or allowed by the new preferences take effect immediately. However, a full page reload is not always desirable — particularly for single-page applications (SPAs) or implementations using progressive consent, where you dynamically load or remove content based on consent state.

DataGrail provides three methods to block this automatic reload.

When to Block Reloads

Blocking page reloads is recommended when:

Callback Requirement

When you block reloads, DataGrail will not automatically enforce the updated preferences on scripts already running on the page. Your development team must use callbacks (preference_callback and initial_preference_callback) to handle consent changes in your application code.

Methods

Choose the method that best fits your deployment.

Method When to Set Use Case
Global variable Before script loads Static configuration at page load
API method After script loads Dynamic, runtime control
Event queue Before or after script loads Flexible integration with tag managers or event-driven platforms

Global Variable

Set the DG_CONSENT_BLOCK_RELOAD global variable to true before the DataGrail Consent script loads. This is the simplest approach for sites that always want reloads blocked.

<script>

window.DG_CONSENT_BLOCK_RELOAD = true;

</script>

<!-- Load DataGrail Consent after setting the variable -->

<script src="https://api.consentjs.datagrail.io/YOUR_CUSTOMER_ID/YOUR_CONTAINER_ID/consent-loader.js"></script>

This variable is checked once during initialization. To change the setting after the script loads, use the API method instead.

API Method

Call window.DG_BANNER_API.blockReload(block) to dynamically enable or disable reload blocking at any time after DataGrail Consent has initialized. This method accepts a boolean parameter — true to block reloads, false to allow them.

// Block reloads

window.DG_BANNER_API.blockReload(true);

// Allow reloads again

window.DG_BANNER_API.blockReload(false);

This is the most flexible approach and works well for SPAs that need runtime control over reload behavior.

Event Queue

Push a block_reload event to the window.dgEvent array. This method works both before and after the DataGrail Consent script loads, making it a reliable option for sites where script load order is unpredictable.

<script>

window.dgEvent = window.dgEvent || [];

window.dgEvent.push({

event: 'block_reload',

block: true

});

</script>

To re-enable reloads later, push a second event with block: false.

Default Behavior

DataGrail Consent only triggers a reload when the visitor's new preferences differ from their existing preferences. If a visitor re-submits the same choices, no reload occurs regardless of this setting.

When reload blocking is active, the banner closes and preferences are saved, but the page remains in its current state. Your application is responsible for responding to the updated preferences through callbacks.

Need help?

If you have any questions, please reach out to your dedicated Account Manager or contact us at support@datagrail.io.

Disclaimer: The information contained in this message does not constitute as legal advice. We would advise seeking professional counsel before acting on or interpreting any material.