Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reload image only if its visible #221

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

shadow974
Copy link

The image widget should not refresh images which is not displayed to the user. It just creates a lot of traffic on mobile connections.

@knowthelist
Copy link
Owner

There idea is quite good, but I don't know if its good to continue counting while the image is not displayed. Have you experienced any overflows? I'd feel better if we could pause/resume the counter ...

@choenig
Copy link

choenig commented Oct 7, 2018

A simple solution would be to just set the counter to refresh if the image is not visible.

This fixes the overflow-issue and makes sure the image is reloaded after it gets visible again (if and only if the refresh time has been reached:

setInterval(function () {
	counter++;
	if (counter >= refresh) {
		if (url.match(/_=\d+/)) {
			url = addurlparam(url, '_', new Date().getTime());
		}   
		ftui.log(2, 'Update image widget source. URL=' + url);
		if (elemImg.is(":visible") == true) { 
			elemImg.attr('src', url);
			counter = 0;
		} else {
			counter = refresh;
		}
	}
}, 1000);

An even simpler solution (code wise) would be to skip the complete update if the image is not visible:

setInterval(function () {
	counter++;
	if (counter >= refresh) {
		if (elemImg.is(":visible") == false) { 
			counter = refresh;
			return;
		}
		counter = 0;
		if (url.match(/_=\d+/)) {
			url = addurlparam(url, '_', new Date().getTime());
		}   
		ftui.log(2, 'Update image widget source. URL=' + url);
		elemImg.attr('src', url);
	}
}, 1000);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants