Giter VIP home page Giter VIP logo

ctstack-nuxt's Introduction

Contentstack

Build Website using Nuxt.js, imgix, and Contentstack

About Contentstack: Contentstack is a headless CMS with an API-first approach that puts content at the centre. It is designed to simplify the process of publication by separating code from content.

About imgix: imgix is an image optimization, management, & delivery API. There's no need to store images on imgix, it instead simply connects to whereever your images are located. For Contentstack, you would simply create a webfolder and point it at https://images.contentstack.io/. Then you can add an imgix SDK library, the Vue SDK in this example for Nuxt, to easily create responsive images.

About this project: Creating an example blog page using imgix with an existing project on Contentstack and Nuxt.

What is imgix doing?

imgix is using their Vue SDK to create responsive images. In this example, imgix is also intelligently formatting the images, which is where the majority of the image weight savings is coming from. For example, if an image is being view in Chrome/Firefox, it is converted to webp. For other browsers, imgix is intelligently checking the image for transparent pixels, returning a png8 (or any format you prefer) for images requiring transparency and pjpgs for non-transparent image types.

imgix is also ensuring images are not being incorrectly cropped. In this example, I am specifically retaining the aspect ratio of images but forcing them all to be 360 x 270 (in the blog preview images), then if the aspect ratio is different I fill in that additional space with the same background color matching the website. This ensures the blog images look similar in size but do not get skewed during any cropping.

Live Demo

You can check the live demo to get first-hand experience of the website.

Comparison

This site was built using the below steps from Contentstack. Of note, the image weight on a Chrome browser was brought down from 23.3 MB to 272 KB, which is a 98.9 % reduction in image weight!

Build Website using Nuxt.js and Contentstack

Steps to add an imgix Library

Install the appropriate imgix library, in this example the Vue library.

npm install vue-imgix

Add a file to the plugins, vue-imgix.js and add this:

import Vue from 'vue';
import VueImgix from 'vue-imgix';

Vue.use(VueImgix, {
    domain: "{your imgix domain}",
    defaultIxParams: {
        auto: 'format,compress'
    },
});

You can then replace any <img /> tags with <ix-img>. For the src, I created a function in methods to remove the host name from the image urls sent by contentstack, which will be replaced by your imgix url in the vue-imgix.js plugin. Like this:

methods: {
    imageSrc() {
      return (new URL(this.data.banner.image.url)).pathname
    }
  }

ctstack-nuxt's People

Contributors

daletom avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.