Hmmm alright, didn't think it would be that simple lol.That gets the current width. At the start of your Javascript you could simply:Code:width = document.documentElement.clientWidth;
Code:width = document.documentElement.clientWidth; if (width < 750) { return false; }
Yeah I'm just getting serious page-blocking on my mobile device (none on desktop and everything is async) so I want to downsize the unnecessary js for mobile users.It's the same premise used for responsive ads, really.
Chances are you'll be just grabbing that width variable as the page loads so the only thing to think about is, strictly speaking it isn't entirely responsive as it is all evaluated during load time. You could get more advanced and start binding functions to various change events in the browser to detect the width dynamically and reinstate scripts that previously stopped running but for something like this it probably isn't worth it.
if (! $('html').hasClass('Responsive') ) {
//code when responsive is turned off
}
Wouldn't that be more intensive since it's searching body for the class 'Responsive'?I prefer doing something like:
Code:if (! $(body).hasClass('Responsive') ) { //code when responsive is turned off }
But there are many ways to do it.
ETA: Nevermind, I see what you mean now. The way Chris has it is good. But instead, use 800px as thats when XenForo (by default, but this can be changed in Style Properties).
The way I have it is for if responsive is toggled off entirely.
I honestly have no idea. JavaScript loads client-side of course so load times can vary quite drastically. But like I said, I misunderstood your question, my apologies.Wouldn't that be more intensive since it's searching body for the class 'Responsive'?
No you answered it just fine Sorry I'm not thinking properly today and my english is suffering.I honestly have no idea. JavaScript loads client-side of course so load times can vary quite drastically. But like I said, I misunderstood your question, my apologies.
Then did I misunderstand your question?No you answered it just fine Sorry I'm not thinking properly today and my english is suffering.
Is there a way to benchmark JS since I would love to see if one is better than the other.
No I got that completely, and you can use both to achieve my question (remove the ! from Audentio's solution), I'm just asking if searching through every class in <body> for 'Responsive' would have lesser performance compared to your solution.Then did I misunderstand your question?
The solutions that myself and Audentio provided were solutions to two completely different scenarios.
If you want to detect that someone is using a smaller screen using Javascript then my solution will work.
If you want to detect when someone is using a style where you have switched the Responsive Design off completely for that style then use Audentio's solution.
You will only need to check once, so you'll want that like this:No I got that completely, and you can use both to achieve my question (remove the ! from Audentio's solution), I'm just asking if searching through every class in <body> for 'Responsive' would have lesser performance compared to your solution.
$(document).ready(function() {
// code when document is ready, asap
});
$(window).on('resize orientationchange load', function(e) {
//code will run every time someone resizes browser or changes orientation, and on load, on their device
});
We use essential cookies to make this site work, and optional cookies to enhance your experience.