Cloudinary's Vue.js SDK is designed to provide a simpler and more enhanced developer experience. This guide explains how to migrate your Vue.js code from the cloudinary-vue library (legacy SDK) to the latest Vue.js SDK, which includes @cloudinary/vue
from the frontend-frameworks library together with @cloudinary/url-gen
from the js-url-gen library.
Key improvements in the Vue.js SDK:
/c_scale,w_400/f_auto/q_auto/
, rather than /c_scale,f_auto,q_auto,w_400/
.Things to know before migrating to @cloudinary/vue + @cloudinary/url-gen
The action-based syntax used in the js-url-gen
library (@cloudinary/url-gen
) may cause URLs to be formed differently from those generated by the cloudinary-vue
library.
For example:
https://res.cloudinary.com/demo/image/upload/c_scale,f_auto,q_auto,w_400/sample.jpg
https://res.cloudinary.com/demo/image/upload/c_scale,w_400/f_auto/q_auto/sample.jpg
Even if the delivered media file looks and behaves identically, changes to URLs can have the following implications:
eager
parameter of the explicit method.To reduce the impact of all of the above, we recommend using the createCloudinaryLegacyURL method for your existing transformation URLs, especially if your existing app delivers a large number of transformed assets. This maintains the formations of the transformations, so the URLs remain the same.
The createCloudinaryLegacyURL
function supports only transformation and configuration parameters. It does not help to migrate HTML tags, responsive, placeholder, transparent video or jQuery functionality.
For all new transformation URLs that you add to your application, we recommend using the new action-based SDK syntax offered by the latest version of the SDK.
For full documentation on using the @cloudinary/vue
+ @cloudinary/url-gen
packages in your Vue.js app, see the Vue.js SDK guide.
Cloudinary's Vue.js package (@cloudinary/vue
from the frontend-frameworks
library) must be used in conjunction with the Cloudinary JavaScript SDK (@cloudinary/url-gen
) to provide all of Cloudinary's transformation and optimization functionality. As such, the latest Vue.js SDK is very different from the cloudinary-vue
(legacy) library in its architecture and usage, so migration paths depend on your current usage of the Vue.js library.
You can use the cloudinary-vue
, @cloudinary/vue
and @cloudinary/url-gen
packages in your application concurrently, so although not recommended for the long term due to the increased bundle size, you could start by integrating @cloudinary/vue
and @cloudinary/url-gen
into your application and slowly migrate your functionality piece by piece, until you are able to remove all cloudinary-vue
functionality.
Install the required packages using the NPM package manager:
Migrating Cloudinary instance configurationUsing the legacy Vue.js SDK, you may be configuring your cloud name and other configuration parameters in a cld-context
. This is similar to configuring these parameters in a Cloudinary
instance, provided by the @cloudinary/url-gen
library, in that the configuration is set once, rather than for each image or video.
For example, setting cloudName
and secure
in a cld-context
element:
is similar to setting cloudName
and secure
in a Cloudinary
instance:
You can also set configuration parameters in cld-image
or cld-video
elements in the legacy Vue.js SDK. This is similar to setting the parameters on a per asset instance.
For example, setting cloudName
in a cld-image
element:
is similar to setting cloudName
in a CloudinaryImage
:
The cld-image
component in cloudinary-vue
has been replaced by the AdvancedImage
component in @cloudinary/vue
.
Whereas in the legacy Vue.js SDK you specify transformation parameters in the cld-image
component, in the latest SDK they are specified in @cloudinary/url-gen
in a CloudinaryImage
object that you then pass to the AdvancedImage
component.
Here is an example of a cld-image
component with configuration and transformation parameters included:
There is no easy migration path from a cld-image
component to an AdvancedImage
component, but you can use the following process as an intermediate step, to create a URL that you can use as the source for a regular image tag:
Convert the cld-image
component to JSON. An XML to JSON converter can help with this transition, or you may want to use a script if you have a large number of URLs to convert. The previous example would become:
Pass this JSON to the createCloudinaryLegacyURL
function, included in the @cloudinary/url-gen
library, to return a delivery URL that includes the transformations. Configuration parameters, such as cloud_name
, should be included in the function call as this is simply a helper function to build the delivery URL:
Use this URL as the source for a regular image tag.
If you have a large number of assets, we recommend you migrate using the
createCloudinaryLegacyURL
method. If you replace your existing transformations using the new SDK transformation syntax, you may find your URLs are generated in a slightly different way. See
Things to know before migrating to @cloudinary/vue + @cloudinary/url-gen, for the implications of these changes to transformation URLs.
For all new Cloudinary delivery URLs, you should start to use the @cloudinary/url-gen
syntax to create a CloudinaryImage
that you can use in the AdvancedImage
Vue.js component:
The resulting URL is:
Migrating advanced image components and responsive functionalityThe advanced image components (lazy loading, image placeholders and image accessibility) and responsive image settings offered by the legacy Vue.js SDK, are offered as plugins in the latest Vue.js SDK.
When you have migrated your delivery URLs to use the AdvancedImage
component, you can use the plugins as follows:
This example shows all four plugins being used, but you can use only one, or any combination, by importing and specifying only those you need.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4