I have an image gallery in my nuxt site running in universal mode (deployed as static page) and would like to add blueimp gallery (a lightbox) to it.
There are several ways to place the Javascript (./static, ./plugins or ./assets).
I'd prefer to use the assets folder since everything I put there is handled by webpack (compression, unique ID for long term client caching).
Since blueimp isn't important during rendering the page but only during interaction (clicking an image to open the lightbox), the javascript should be loaded just before the end of </body>
Another thing is, that I need blueimp only on a dedicated page, so if possible the blueimp-gallery.min.js and it's css shoudn't be served on the other pages.
JS
I got it running in yarn dev mode (which supports SSR) by including the script from the static folder in head and add body: true to it (to not use head ;) ) .
In production (as a static page), it doesn't work.
The parameter ssr: false seems to have no effect. Also adding <client-side> around the image component in the template doesn't help.
Question 1: I'd be glad if you could help me to rewrite this into a clientside function (maybe with another hook like created() or mounted() ?)
<script>
export default {
head: {
script: [
{
src: 'js/blueimp-gallery/blueimp-gallery.min.js',
body: true,
ssr: false,
},
],
},
},
</script>
CSS
I am able to load a css file from the static folder with the code below. Unfortunately this adds an extra request.
<template>
...
</template>
<script>
export default {
head: {
style: [{ src: "blueimp-gallery/css/blueimp-gallery.min.css", head: true }],
},
}
</script>
Loading it with @import even fetches it from the assets folder and embeds it into the page which is nice, but it's being embedded into all pages.
<style>
@import '~/assets/styles/blueimp-gallery/css/blueimp-gallery.min.css';
</style>
Found another way here, which is probably the best: loading a css file from 'assets' directory in a NUXT layout
link: [{ rel: 'stylesheet', href: require('~/assets/blueimp-gallery/css/blueimp-gallery.min.css')}],
Question 2: Maybe you have an improved solution for embedding the CSS into a single page?
I'm a beginner, so if you have a solution please add some examples with a little context.