scottsweb / wp-instagram-widget

❌ A WordPress widget for showing your latest Instagram photos.
115 stars 62 forks source link

Local image hosting #89

Closed ste7enm closed 4 years ago

ste7enm commented 6 years ago

Would love to see an option to scrape Instagram at X frequency, but then cache and host up the images locally, almost similar in a way to the way this Gravatar plug-in works.

Instagram is sometimes contributing to up to 4 seconds in my waterfall for only 5 images.

feastdesignco commented 6 years ago

Was thinking this exact thing.

This would reduce the overhead the plugin contributes to a pageload. Would be happy to donate to have this done.

ste7enm commented 6 years ago

Good call. I'd throw $20 at a PayPal.me for this 👍.

scottsweb commented 6 years ago

It seems like a good idea but it will need some thinking through. Potential stumbling blocks are:

  1. Filling up the local media library
  2. Making sure we can safely write the files (not all hosting provides a writable directory, need to use the correct WP hooks in case a sites media is stored elsewhere)
  3. Making sure we have generated the various different sizes of the main image that the plugin needs
  4. Support local CDN setups

I think the main contributor to page load is not the grabbing of the images (that happens once every couple of hours and can easily be offloaded without the user knowing - aiming to do this in #39), it is mostly likely that we are not making good use of the Instagram CDN. We cache the URLs that are closest to the server, not the visitor.

feastdesignco commented 6 years ago

Interesting points. Anecdotally:

  1. 4-10 images shouldn't fill any media library - if it's purging the previous images and re-caching the most recent posts daily, there should never be more than 1-mb cached.

  2. Checking for successfully cached images and falling-back to loading from IG should resolve this. eg. if_file_exists(images/wpiw_cache1.jpg){load_from_local}else{load_from_ig}

  3. I couldn't comment on this aspect.

  4. This is a very fringe case but good for you for considering. I can't image more than 1% of the installed base would encounter this.

The main issue with pagespeed becoming a concern is loading third-party content involves additional DNS lookups. Pulled from a live site:

igcontent-load

That's 90ms/140ms spent establishing a connection. If it can be lazyloaded it's not so problematic (we typically see it installed at the bottom of the page) but if it's render-blocking then almost 100ms is significant.

ste7enm commented 6 years ago

Yeah, I'd imagine it having a dedicated folder (made writable, per 2, advanced users only) so that it didn't filter into and bog down the Media Library (1).

Agreed the strain that I'm observing is the actual loading of the images from Instagram's CDN. Seeing it on every page load hurts my optimization-obsessed heart.

feastdesignco commented 6 years ago

Further to above, server side caching would help avoid Instagram "fixing" end points that cause image loading to fail: https://github.com/scottsweb/wp-instagram-widget/issues/100#issuecomment-409294920

It would reduce the number of hits to Instagram's endpoints, making it less of concern for them to "fix". Fly under the radar.

scottsweb commented 4 years ago

This project is being archived (background in #118). Instagram filed a trademark complaint which saw the plugin removed from WordPress.org and then proceeded to block it from accessing instagram.com. All issues are being closed and it will soon be in a read only state.

ste7enm commented 4 years ago

Damn shame, this was a really great one, @scottsweb. Good luck with your other projects and thank you, on behalf of the community, for your work on this one.

scottsweb commented 4 years ago

Thanks :)