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

Prefetch the medium photo instead of the big one #446

Closed
wants to merge 2 commits into from

Conversation

Bramas
Copy link
Contributor

@Bramas Bramas commented Jan 16, 2016

This PR is related to the issue #185
I added the medium photo url in each photo of the album,
Then this url is used instead of the big photo url when prefetching the next photo.

The problem is that we don't know which photo is loaded by the browser because some browsers don't understand srcset with 'w' parameter.
But I think it's better to preload the medium and hope for the browser to use it (possible 1~2 Mo lost on old browser or on 4K screen if not), instead of preloading the big one and lose 10 Mo every photo on a recent browser.

@Bramas
Copy link
Contributor Author

Bramas commented Jan 16, 2016

Also, In the case the screen of the user is bigger that 1920px then the prefetched medium photo is lost.
What we can do is add a media query in the link: <link rep='prefetch' media='(max-width: 1920px)' MEDIUM_URL>
and we can even add another link <link rep='prefetch' media='(min-width: 1920px)' BIG_URL>

@electerious
Copy link
Owner

Do you know if rel="prefetch" and media='(min-width: 1920px)' works together? I never heard about this combination. Would be great, thought.

@Bramas
Copy link
Contributor Author

Bramas commented Jan 18, 2016

I just checked it out and unfortunately rel="prefetch" and media='(min-width: 1920px)' do not work together. It is even worse, because even when using rel="stylesheet" with the media attribute, even if the condition of the media query is not satisfied, the stylesheet is downloaded. So it cannot prevent the prefetch of a photo.
If we want to prefetch the right picture depending on the viewport, we will have to wait for a way to detect which picture has been loaded by the browser with the srcset attribute, and then use this to prefetch the other photos (found nothing on stackoverflow about that).

Without more information, I think the medium photo is the right one to prefetch.

@electerious
Copy link
Owner

electerious commented Jul 2, 2016

Implemented. Can you take a look at it? 1b8dd24

@electerious electerious mentioned this pull request Aug 22, 2016
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.

2 participants