How can I configure Webflow so that the preloader only appears during the first visit to the website?

TL;DR
  • Design a preloader in Webflow, set up page load interactions, and add custom JavaScript code to store a cookie.
  • The JavaScript checks if the user has visited before; if not, the preloader shows, otherwise, it is skipped.

To configure Webflow to show a preloader only on the first visit, you can utilize a combination of Webflow's interactions and custom code to store a cookie in the user's browser. Here's how you can achieve this:

1. Create and Design the Preloader

  • Design your preloader in Webflow using div blocks or animations as desired.
  • Ensure the preloader has a unique identifier, such as a class or ID, for targeting.

2. Set Up Interactions for the Preloader

  • Go to Interactions in the Webflow Designer.
  • Create a new Page Load Animation to show or scale the preloader during the first time the page loads.

3. Add Custom Code to Store and Check a Cookie

  • Access Custom Code by going to the Page Settings of the page where the preloader is used.
  • Paste the following JavaScript snippet into the "Before </body> tag" section to manage the cookie:

<script>
  document.addEventListener("DOMContentLoaded", function() {
    var hasVisited = document.cookie.split(';').some(item => item.trim().startsWith('visited='));
    var preloader = document.querySelector('#your-preloader-id'); // Replace with your preloader ID or class

    if (!hasVisited) {
      document.cookie = "visited=true; max-age=31536000"; // 1 year
      // Keep preloader visible or initial animation
    } else if (preloader) {
      preloader.style.display = 'none';
    }
  });
</script>
  • Replace #your-preloader-id with the actual ID or class of your preloader element.

4. Test Your Implementation

  • Publish and test your site to ensure the preloader only appears during the initial visit and is skipped in subsequent loads.

Summary

To have a Webflow preloader appear only on the first visit, design the preloader, create load interactions, and use custom JavaScript code to check and set a cookie. This way, the preloader will only be visible to users who have not yet visited your site, enhancing the user experience.

Rate this answer

Other Webflow Questions