I have created a custom module in which I created a popup modal in custom location.js with require js on and add this js in default.xml file.
On the first page load popup is open after the page load i want to load this js before the page load.
Here's the default.xml wihich I override
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
 <link src="Vendor_Module::js/location.js"/>
</head>
<body>
 <referenceContainer name="page.wrapper">
 <block class="Magento\Framework\View\Element\Template" name="custom-block-name" template="Vendor_Module::popup.phtml" ifconfig="nearbyproducts/general/enable"/>
 </referenceContainer>
</body>
Can you please suggest how can I load js before page load or stop the page load?
- 
 Hi Divya, your question is bit unclear for me. Can you elaborate a little more? what is your js file actually trying to do? I dont think stopping page load for a js file is a good idea. Javascript files are by default blockers during page load unless you make them async.Rajeev K Tomy– Rajeev K Tomy2022年09月25日 06:14:23 +00:00Commented Sep 25, 2022 at 6:14
 - 
 Hi there , can you please share the script here ? I am guessing you could move your script in the head tag and write events that when a dom element is loaded it could trigger.Bharath Kumar– Bharath Kumar2022年09月25日 08:33:38 +00:00Commented Sep 25, 2022 at 8:33
 - 
 Hi @RajeevKTomy, I created a Zipcode popup in js file when we enter zipcode then products will be come according to distance.Divya Rawat– Divya Rawat2022年09月25日 11:27:42 +00:00Commented Sep 25, 2022 at 11:27
 - 
 Hi @RajeevKTomy, Issue is that In catalog product page when I enter zipcode product are come from cache they will not short and after clean the cache product will show correctly. I hope it's clear for you.Divya Rawat– Divya Rawat2022年09月25日 11:50:02 +00:00Commented Sep 25, 2022 at 11:50
 
default