Jasonette / JASONETTE-iOS

📡 Native App over HTTP, on iOS
https://www.jasonette.com
MIT License
5.27k stars 352 forks source link

Support for Link Prefetching #60

Open gtramontina opened 7 years ago

gtramontina commented 7 years ago

Hey there,

I was thinking about how to speed up navigation and remembered the case where some flickr pictures were getting deleted because some browsers where prefetching links. But, flickr had implemented DELETE as GET… ¬_¬ lovely!

Anyway, these days HTML supports adding prefetch (and the likes) hints to the browser so it speeds up certain aspects of the navigation.

As part of that, there's also lazy loading images (which could be its own separate GH issue)… A quick search in this repository gave me a couple of hints that the library we're using to render images already support it (?).

gliechtenstein commented 7 years ago

Please correct me if I'm misunderstanding how prefetch works, but isn't prefetching kind of dangerous on a mobile context?

One potential problem I can see is : People getting charged for all the 3G/LTE traffic on their phone even when they didn't even visit the corresponding view (I think prefetch makes sense on a desktop context in this sense since most people access the internet via wifi and don't need to worry about traffic cost)

gtramontina commented 7 years ago

I guess I can see it being misused… true. But I also see it some benefits 😄, specially if we're using the templates functionality and gzipping. We don't need to fetch all images or run the network actions of the "next" links marked with prefetch just yet. Only when we effectively navigate into that view, which would be a smooth transition. This is for sure one of those "use judiciously" type of things. Anyway, I thought this could be a good addition, if not to the core, as an extension.

How about lazy loading images?


edit:

(…) specially if we're using the templates functionality and gzipping …

… and proper caching.

gliechtenstein commented 7 years ago

As for image lazy loading, thanks for bringing that up. Actually lazy loading is how iOS handles image loading natively. It only renders images that are in the current viewport.

In fact it is Jasonette that manually prefetches all images because in some cases it's useful. For example offline caching wouldn't work completely without prefetching all images (since iOS would only load the images that were visible at the time you opened the app last time).

But I do think we should try adding an option to choose between lazy loading and prefetching images. Maybe open this as a separate issue?


As for the template prefetching idea, I think it could work for cases when each item links to the same link (with the same template), since you only need to prefetch once.

But what if we have 500 items on the screen, each with different link? Won't we still have to fetch them all in order to know if they have the same template or not?

Maybe it's most straight forward if we talk code. Do you have in mind an example of how this could be expressed in JSON?

gtramontina commented 7 years ago

But what if we have 500 items on the screen, each with different link?

This is why it would come labeled as use judiciously… 😄 This shouldn't be enabled by default.

Here's a sketch of what I have in mind…

{
  "type": "label",
  "text": "Push me",
  "href": {
    "url": "https://www.jasonclient.org/next.json",
    "prefetch": "true"
  }
}

There's a lot more to prefetching, but the immediate benefit I see here is to provide a smoother transition between screens, and the example above tries to reflect that.

gliechtenstein commented 7 years ago

Aha, that makes sense! Yeah I think this is something we could potentially support in the future. Let's sit on it for a while :)

p.s. If anyone comes across this and has some ideas on why this will be useful for them, feel free to comment.