How can I run a specific .js script if url matches "/search" or run a different .js script if the url is different using if/else statement? This would go in head section and either are used to build the DOM based on the url.
Would the code below work? Any help appreciated!
if (window.location.pathname === '/search') {
<script type="text/javascript" src="file1.js"></script>;
}
else {
<script type="text/javascript" src="file2.js"></script>;
}