Skip to Content
Menu
This question has been flagged
1 Reply
2210 Views

I have a google map store locator on my home page inside a div called storepoint-container . This is the code for getting the script for the same


<template id="assets_frontend" name="Google Map " inherit_id="web.assets_frontend">

        <xpath expr="//script[last()]" position="after">

            <script>(function() {

        var a = document.createElement("script");

        a.type = "text/javascript";

        a.async = !0;

        a.src = "https://cdn.storepoint.co/api/v1/js/storepoint.js";

        var b = document.getElementsByTagName("script")[0];

        b.parentNode.insertBefore(a, b);}());</script>

        </xpath>

    </template>


While this is working fine on the home page I'm getting a CDN error every time I try to open any other pages within the website. How can I fix this?

Avatar
Discard
Best Answer

Hi,
It’d be better if you could provide more details like error logs.

From what we can see if no conflict is on the home page, this conflict could be caused in other pages, as you are not using the store locator in them, meaning the storepoint-container div is not available thus creating a conflict since null value is received where storepoint-container div is expected while front end assets are being loaded.


So you can try adding a condition within the script to check whether the element is available by fetching the div into a variable and check if the variable is null, like this,

<template id="assets_frontend" name="Google Map " inherit_id="web.assets_frontend">
<xpath expr="//script[last()]" position="after">
<script>(function() {
var element = document.getElementById("storepoint-container");
if (element == null) {
return;
} else {
var a = document.createElement("script");
a.type = "text/javascript";
a.async = !0;
a.src = "https://cdn.storepoint.co/api/v1/js/storepoint.js";
var b = document.getElementsByTagName("script")[0];
b.parentNode.insertBefore(a, b);
}
}());</script>
</xpath>
</template>

Regards

Avatar
Discard
Author

This works, you are a life saver, thanks.