All things Shopify and commerce
Dear shopify,
I want to have a preloading image when open the pages in the website.
MY Theme is dawn theme.
Kindly share code on how to add the preload
Thank you
Solved! Go to the solution
This is an accepted solution.
To add a preloader image when opening pages on your Dawn theme Shopify website, you can follow these steps:
<div class="preloader">
<img src="{{ 'preloader.gif' | asset_url }}" alt="Preloader">
</div>
<style>
.preloader {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: #fff;
z-index: 9999;
display: flex;
justify-content: center;
align-items: center;
}
</style>
<script>
window.addEventListener('load', function() {
var preloader = document.querySelector('.preloader');
preloader.style.display = 'none';
});
</script>
<body>
{% section 'preloader' %}
...
</body>
Here's how it works:
By including the preloader.liquid section in your theme.liquid file, the preloader will be displayed on all pages of your website until the page is fully loaded.
Make sure to replace 'preloader.gif' with the actual filename of your preloader image. With these steps, you should have a preloader image displayed when opening pages on your Dawn theme Shopify website.
I hope this helps.
Was this helpful? Like or Accept solution - Buy me a coffee ☕️
- Contact me: Xipirons | WhatsApp
- Shopify Developer based in France, helping online merchants succeed
This is an accepted solution.
To add a preloader image when opening pages on your Dawn theme Shopify website, you can follow these steps:
<div class="preloader">
<img src="{{ 'preloader.gif' | asset_url }}" alt="Preloader">
</div>
<style>
.preloader {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: #fff;
z-index: 9999;
display: flex;
justify-content: center;
align-items: center;
}
</style>
<script>
window.addEventListener('load', function() {
var preloader = document.querySelector('.preloader');
preloader.style.display = 'none';
});
</script>
<body>
{% section 'preloader' %}
...
</body>
Here's how it works:
By including the preloader.liquid section in your theme.liquid file, the preloader will be displayed on all pages of your website until the page is fully loaded.
Make sure to replace 'preloader.gif' with the actual filename of your preloader image. With these steps, you should have a preloader image displayed when opening pages on your Dawn theme Shopify website.
I hope this helps.
Was this helpful? Like or Accept solution - Buy me a coffee ☕️
- Contact me: Xipirons | WhatsApp
- Shopify Developer based in France, helping online merchants succeed
Thank you very much for your response. You explained very well.
Yes, you can hide the preloader once the main content is partially rendered on the screen instead of waiting for the entire page to load. Here's how you can modify the code to achieve that:
<div class="preloader">
<img id="loader" height="50px" width="50px" src="{{ 'preloader.gif' | asset_url }}" alt="Preloader">
</div>
<style>
.preloader {
pointer-events: none;
cursor: default;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100vh;
background-color: #fff;
z-index: 9999;
display: flex;
justify-content: center;
align-items: center;
}
#loader {
position: absolute;
width: 100px;
height: 100px;
z-index: 999;
}
</style>
<script>
document.addEventListener('DOMContentLoaded', function() {
var preloader = document.querySelector('.preloader');
preloader.style.display = 'none';
});
</script>
Here are the changes made:
1. Changed the position property of the .preloader class to fixed instead of relative. This ensures that the preloader covers the entire viewport regardless of the page's scroll position.
2. Changed the event listener from window.addEventListener('load', ...) to document.addEventListener('DOMContentLoaded', ...). The DOMContentLoaded event fires when the initial HTML document has been completely loaded and parsed, without waiting for stylesheets, images, and subframes to finish loading. This means the preloader will be hidden as soon as the main content is ready, even if some resources are still loading.
With these modifications, the preloader will be displayed until the main content is loaded and parsed, and then it will be hidden, allowing the user to see the partially rendered content while the remaining resources continue to load in the background.
Keep in mind that the exact timing of when the preloader is hidden may vary depending on the complexity and size of your page's content. If you have a lot of content that needs to be loaded and parsed, there might still be a slight delay before the preloader is hidden.
However, this approach should generally provide a faster perceived loading experience compared to waiting for the entire page to load.
Was this helpful? Like or Accept solution - Buy me a coffee ☕️
- Contact me: Xipirons | WhatsApp
- Shopify Developer based in France, helping online merchants succeed
Thanks a lot , your solution worked very well.
can i show only once time when site load and show only home page not all pages when i go to another page loader showing but i dont want loader on other pages
make a preloader.liquid file and add the below code, replace the image file path and
then in theme.liquid add bellow lines before closing body tag.
{% section 'preloader' %}
<!-- Preloader starts -->
<div class="preloader">
<img id="loader" height="100px" width="100px" src="https://cdn.shopify.com/s/files/1/0580/2881/8526/files/Loading_animation.gif?v=1726142050" alt="Preloader">
</div>
<!-- Preloader ends -->
<style>
.preloader {
pointer-events: none;
cursor: default;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100vh;
background-color: #fff;
z-index: 9999;
display: flex;
justify-content: center;
align-items: center;
}
#loader {
position: absolute;
width: 100px;
height: 100px;
z-index: 999;
}
</style>
<script>
document.addEventListener('DOMContentLoaded', function() {
var preloader = document.querySelector('.preloader');
// Increase the showing time (e.g., 3 seconds delay)
setTimeout(function() {
preloader.style.display = 'none';
}, 3000); // 3000 milliseconds = 3 seconds
});
</script>
Starting a B2B store is a big undertaking that requires careful planning and execution. W...
By JasonH Sep 23, 2024By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024