I have two ad scripts, one for desktop and one for mobile. Currently, one is set to display: none
on a certain size and so on. I'm looking to prevent the script that is currently not shown from running whatsoever, because the scripts tend to be resource intensive and I'm trying to speed up the page load time. Is there any way to only make scripts execute at a certain width?
I was thinking:
if ($(window).width >= 768px) {
<script> Do stuff </script>
} else {
<script> Do stuff </script>
}
However I've had no luck with this (I'm not sure how a script within a script would work). Is there another way to go about this?