Skip to content

Commit bb534cd

Browse files
committed
feat(theme): add LoadWhenVisible component and lazyload footer
- update social icons to reduce weight and increase quality - load footer only when visible
1 parent 4c2dbcc commit bb534cd

File tree

8 files changed

+67
-43
lines changed

8 files changed

+67
-43
lines changed

packages/theme/components/AppFooter.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ export default {
120120
}
121121
&__social-image {
122122
margin: 0 var(--spacer-2xs) 0 0;
123+
background-color: #fff;
124+
border-radius: 100%;
123125
}
124126
}
125127
.sf-footer {
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<template>
2+
<div ref="root">
3+
<slot v-if="isVisible" />
4+
</div>
5+
</template>
6+
<script>
7+
import {
8+
defineComponent, onMounted, onUnmounted, ref,
9+
} from '@nuxtjs/composition-api';
10+
11+
export default defineComponent({
12+
name: 'LoadWhenVisible',
13+
setup() {
14+
const isVisible = ref(false);
15+
const root = ref(null);
16+
17+
let observer = null;
18+
if (process.browser && ('IntersectionObserver' in window)) {
19+
observer = new IntersectionObserver((entries) => {
20+
if (entries[0].intersectionRatio <= 0) return;
21+
observer.unobserve(root.value);
22+
isVisible.value = true;
23+
});
24+
}
25+
26+
onMounted(() => {
27+
if (observer) {
28+
observer.observe(root.value);
29+
}
30+
});
31+
32+
onUnmounted(() => {
33+
if (observer) {
34+
observer.unobserve(root.value);
35+
}
36+
});
37+
38+
return {
39+
root,
40+
isVisible,
41+
};
42+
},
43+
});
44+
</script>

packages/theme/layouts/default.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
<nuxt :key="route.fullPath" />
1515
</div>
1616
<BottomNavigation />
17-
<AppFooter />
17+
<LoadWhenVisible>
18+
<AppFooter />
19+
</LoadWhenVisible>
1820
</div>
1921
</template>
2022

@@ -27,6 +29,7 @@ import {
2729
useUser,
2830
} from '@vue-storefront/magento';
2931
import useUiState from '~/composables/useUiState.ts';
32+
import LoadWhenVisible from '~/components/LoadWhenVisible';
3033
3134
import { useMagentoConfiguration } from '~/composables/useMagentoConfiguration';
3235
import AppHeader from '~/components/AppHeader.vue';
@@ -37,6 +40,7 @@ export default defineComponent({
3740
name: 'DefaultLayout',
3841
3942
components: {
43+
LoadWhenVisible,
4044
LazyHydrate,
4145
AppHeader,
4246
TopBar,
Lines changed: 1 addition & 4 deletions
Loading

packages/theme/static/icons/google.svg

Lines changed: 1 addition & 10 deletions
Loading

packages/theme/static/icons/pinterest.svg

Lines changed: 5 additions & 9 deletions
Loading

packages/theme/static/icons/twitter.svg

Lines changed: 1 addition & 10 deletions
Loading

packages/theme/static/icons/youtube.svg

Lines changed: 8 additions & 9 deletions
Loading

0 commit comments

Comments
 (0)