Skip to content

Commit

Permalink
perf: lazy load model-viewer lib
Browse files Browse the repository at this point in the history
  • Loading branch information
RomainLanz committed Jan 28, 2024
1 parent c7621d2 commit 56cae0e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
14 changes: 14 additions & 0 deletions resources/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,17 @@ createInertiaApp({
.mount(el)
},
})

window.requestIdleCallback(() => {
const scriptEl = document.createElement('script')
scriptEl.src = 'https://ajax.googleapis.com/ajax/libs/model-viewer/3.3.0/model-viewer.min.js'
scriptEl.async = true
scriptEl.onload = () => {
const modelViewerEls = document.querySelectorAll('model-viewer[data-not-loaded]')

for (const modelViewerEl of modelViewerEls) {
modelViewerEl.removeAttribute('data-not-loaded')
}
}
document.body.appendChild(scriptEl)
})
1 change: 1 addition & 0 deletions resources/components/hero.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import Button from '@/components/ui/button.vue'
</div>

<model-viewer
data-not-loaded
alt="AdonisJS 3d logo"
class="hidden h-110 flex-1"
md="block"
Expand Down
7 changes: 7 additions & 0 deletions resources/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,12 @@ body .v-popper--theme-tooltip .v-popper__inner {

body .v-popper--theme-tooltip .v-popper__arrow-outer {
@apply border-base4 backdrop-blur;
}

model-viewer {
height: 440px;
}

model-viewer[data-not-loaded] {
@apply hidden;
}

0 comments on commit 56cae0e

Please sign in to comment.