This plugin adds the ability to source fetch and cache recent Instagram images so that they can be served as part of the site from the same domain, rather than serving directly from Facebook's Instagram CDN.
Some browser settings and extensions throttle or block serving assets from Facebook's CDN for privacy reasons. Serving these assets directly from the same CDN and domain as the rest of the site should give a small performance benefit too.
This plugin requests data from Instagram feed that you associated with an Instagram Key that you will need to provide as an environment variable. It will save this data as JSON in the Netlify build cache and only re-request the feed after a specified time-to-live value has elapsed. It will also save all the image assets in the Netlify Build cache between builds and place them in the specified location for your static site generator to use.
Configure this plugin to present the gathered data and images in the appropriate location, so your chosen static site generator can leverage it during the build.
See this plugin being used in this simplified demo site: https://demo-netlify-plugin-add-instagram.netlify.app/
To include this plugin in your site deployment:
# Add the plugin as a dependency of your build
npm i --s netlify-plugin-add-instagram
This plugin will fetch the specified instagram feed and the latest 12 images and stash them prior to the execution of the build
command you have specified in your Netlify configuration. The desired Instagram username and various caching attributes can be specified in the netlify.toml
config file as shown below.
# Config for the Netlify Build Plugin: netlify-plugin-add-instagram
[[plugins]]
package = "netlify-plugin-add-instagram"
[plugins.inputs]
# Where to put the image files
imageFolder = "src/images/instagram"
# Also stash data about the images in a json file
dataFile = "src/_data/instagram.json"
# How many seconds should we cache the instagram feed for?
feedTTL = 30
# How many seconds should we cache each instagram image for?
imageTTL = 1209600 # 2 weeks
# Which of Instagram's image sizes should we fetch?
# t (thumbnail)
# m (medium)
# l (large)
imageSize = "m"
# Instagram username
username = "philhawksworth"
Visit the Build Plugins page in the Netlify Admin to enable build plugins on your site.
You can try out this plugin by deploying a simple site which uses it.
Clicking the button below will clone a test site repo, setup a new site on Netlify and deploy the site complete with the plugin configured and operational.