Cloudinary Blog

Introducing Cloudinary's Nuxt Module

By
Introducing Cloudinary's Nuxt Module

Since its initial release in October 2016 by the Chopin brothers as a server-side framework that runs on top of Vue.js, Nuxt (aka Nuxt.js) has gained prominence in both intuitiveness and performance. The framework offers numerous built-in features based on a modular architecture, bringing ease and simplicity to web development. Not surprisingly, Nuxt.js has seen remarkable growth in adoption by the developer community along with accolades galore. At this writing, Nuxt has earned over 30K stars on GitHub and 96 active modules with over a million downloads per month. And the upward trend is ongoing.

Nuxt Downloads

This post describes the benefits Nuxt affords modern web development and the procedures for uploading and optimizing media files in Nuxt with its new Cloudinary module.

What Benefit Does Nuxt Offer?

By eliminating code distribution of server and client, Nuxt offers a straightforward and intuitive project-starter template:

Copy to clipboard
yarn create nuxt-app your-project-name

Conveniently, you can configure your project settings while installing Nuxt, for example:

new nuxt

Nuxt’s built-in, folder-based routing system automates the generation of routes.

Structure of the Nuxt Project Template Structure of the Nuxt Project Template

Also, with a few codelines, you can output your project’s codebase as regular server-side rendering, as a full static site, or as a single-page application (SPA), like this:

Copy to clipboard
/* nuxt.config.js */
export default {
 mode: 'universal', // or 'spa'
 target: 'static', // for static site generation
}

That's not all. Read on for three more amazing capabilities offered by Nuxt.

SEO Improvements

Unlike regular SPAs, Nuxt's SPA build mode combines the server side’s auto pre-generating the static content before sending it back to the browser as static markup. Such a step reduces loading time while enabling Google to crawl the site at ease.

Full Static Site (Jamstack) Rendering With Nuxt SPA

To keep up with the Jamstack trend, Nuxt introduced a while ago the nuxt generate command with smart build-caching, which is probably the most significant innovation move in the framework’s history. That command does the following:

  • Build a static version of your web project.
  • Generate all the pages during the build process and place them in their route directory.
  • Cache the previous build and, if the command detects no changes in the codebase during the new deployment, reuse that build, eliminating the need for a web server.

Headless CMS Through Nuxt’s Content Module

Nuxt’s content module (@nuxt/content) acts as a Git-based, headless CMS for managing content from Markdown, YAML, and CSV files stored in the same project directory, displaying it in your Nuxt app. Perform these two steps to adopt this module:

  1. Install the package: yarn add @nuxt/content #OR npm i @nuxt/content

  2. Add the module to nuxt.config.js:

    Copy to clipboard
    export default {
    modules: [ '@nuxt/content' ]
    }

    Now you can fetch content with the instance $content and display the content with the Vue component <nuxt-content>:

    Copy to clipboard
    <template>
    <nuxt-content :document="document" />
    </template>
    <script>
    export default {
    async asyncData({ $content }) {
        /* fetch content from the file "hello-world" located in content/posts folder */
        const document = await $content('posts/hello-world').fetch()
    
        return { document }
    }
    }
    </script>

Dynamic and Inspired Community

Nuxt boasts a very well-maintained developer community, complete with a host of useful resources:

What is the Procedure for Uploading and Optimizing Media Assets in Nuxt With Cloudinary?

The latest Nuxt integration module from Cloudinary offers you straightforward APIs to efficiently upload and optimize media files. To set up Cloudinary in Nuxt, run this command:

Copy to clipboard
yarn add @nuxtjs/cloudinary #or npm i @nuxtjs/cloudinary

Next, configure your Cloudinary module:

Copy to clipboard
/*nuxt.config.js*/
export default {
    modules: [
        "@nuxtjs/cloudinary"
    ],
    cloudinary: {
        cloudName: "your-cloud-name",
        apiKey: "your-API-key",
        apiSecret: "your-API-secret"        
    }
}

You can then use Cloudinary in your Nuxt app. For instance: * To transform an image and get its delivery URL: $cloudinary.image.url("image-public-id", { width: 300, height: 300, crop: "thumbnail" })

  • To fetch a remote image and transform it:

    Copy to clipboard
    $cloudinary.image.fetchRemote("image-url", {
    width: 300,
    height: 300,
    crop: "thumbnail"
    })
  • To transform a video and get its URL: $cloudinary.video.url("video-publid-id", { width: 300, height: 300, crop: "crop" })

  • To upload and transform media assets:

    Server-Side Upload

    Copy to clipboard
    /* server-side */
    const image = $cloudinary.upload("file-base64-url",{
    public_id: 'example',
    eager: [{
        gravity: 'auto',
        width: 300,
        height: 300,
        crop: 'crop'
    }]
    }

    Client-Side Upload With an Upload Preset

    Copy to clipboard
    /* server-side */
    const image = $cloudinary.upload("file-base64-url",{
    public_id: 'example'
    upload_preset: 'example_preset'
    }
  • To optimize and display an image with a placeholder through a component:

    Copy to clipboard
    <cld-image public-id="image-public-id" width="300" height="300" crop="thumbnail">
    <cld-placeholder type="blur" />
    </cld-image>

What’s Next With Cloudinary’s Capabilities?

Now that Cloudinary is integrated with Nuxt, you can optimize further in numerous ways, especially in combination with the Nuxt Content module, e.g.: * Retrieve and display media assets in your app during build time. * Upload and optimize local assets with content hooks before displaying the content. Also, you can seamlessly serve images and videos with ready-to-use components. Do have a try!

Want to Learn More?

Recent Blog Posts

Our $2B Valuation

By
Blackstone Growth Invests in Cloudinary

When we started our journey in 2012, we were looking to improve our lives as developers by making it easier for us to handle the arduous tasks of handling images and videos in our code. That initial line of developer code has evolved into a full suite of media experience solutions driven by a mission that gradually revealed itself over the course of the past 10 years: help companies unleash the full potential of their media to create the most engaging visual experiences.

Read more
Direct-to-Consumer E-Commerce Requires Compelling Visual Experiences

When brands like you adopt a direct–to-consumer (DTC) e-commerce approach with no involvement of retailers or marketplaces, you gain direct and timely insight into evolving shopping behaviors. Accordingly, you can accommodate shoppers’ preferences by continually adjusting your product offering and interspersing the shopping journey with moments of excitement and intrigue. Opportunities abound for you to cultivate engaging customer relationships.

Read more
Automatically Translating Videos for an International Audience

No matter your business focus—public service, B2B integration, recruitment—multimedia, in particular video, is remarkably effective in communicating with the audience. Before, making video accessible to diverse viewers involved tasks galore, such as eliciting the service of production studios to manually dub, transcribe, and add subtitles. Those operations were costly and slow, especially for globally destined content.

Read more
Cloudinary Helps Minted Manage Its Image-Generation Pipeline at Scale

Shoppers return time and again to Minted’s global online community of independent artists and designers because they know they can count on unique, statement-making products of the highest quality there. Concurrently, the visual imagery on Minted.com must do justice to the designs into which the creators have poured their hearts and souls. For Minted’s VP of Engineering David Lien, “Because we are a premium brand, we need to ensure that every single one of our product images matches the selected configuration exactly. For example, if you pick an 18x24 art print on blue canvas, we will show that exact combination on the hero images in the PDF.”

Read more
Highlights on ImageCon 2021 and a Preview of ImageCon 2022

New year, same trend! Visual media will continue to play a monumental role in driving online conversions. To keep up with visual-experience trends and best practices, Cloudinary holds an annual conference called ImageCon, a one-of-a-kind event that helps attendees create the most engaging visual experiences possible.

Read more