Skip to content

Reload image only if its visible#221

Open
shadow974 wants to merge 1 commit intoknowthelist:masterfrom
shadow974:master
Open

Reload image only if its visible#221
shadow974 wants to merge 1 commit intoknowthelist:masterfrom
shadow974:master

Conversation

@shadow974
Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown

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