Skip to content

Commit

Permalink
Merge pull request #159 from Docent-Inc/feature/리소스최적화
Browse files Browse the repository at this point in the history
Feature/리소스최적화 - 이미지 로딩 개선 및 빌드 옵션 추가
  • Loading branch information
yusiny authored Jan 24, 2024
2 parents a1cadbb + bf7c846 commit f65a587
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 10 deletions.
44 changes: 44 additions & 0 deletions components/common/SkeletonImage.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<template>
<div class="skeleton-image">
<img v-lazyload="url" ref="imgRef" @load="isLoading = false" v-once />
<div class="skeleton" v-if="isLoading"></div>
</div>
</template>

<script>
export default {
name: "SkeletonImage",
props: {
url: {
type: String,
default: "",
},
},
data() {
return {
isLoading: true,
};
},
};
</script>
<style lang="scss" scoped>
@import "@/assets/scss/mixins.scss";
.skeleton-image {
width: 100%;
height: 100%;
position: relative;
img {
position: absolute;
width: 100%;
height: 100%;
}
.skeleton {
position: absolute;
@include skeleton;
width: 100%;
height: 100%;
}
}
</style>
8 changes: 3 additions & 5 deletions components/diary/BoardDiary.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div class="item-board-diary" @click="showDetail">
<img v-if="diary.image_url !== ''" v-lazyload="diary.image_url" />
<SkeletonImage v-if="diary.image_url !== ''" :url="diary.image_url" />
<div v-else class="diary-contents">
<div v-if="diary.diary_name === ''">
<div class="diary-text-only">
Expand All @@ -22,8 +22,10 @@
</div>
</template>
<script>
import SkeletonImage from "~/components/common/SkeletonImage.vue";
export default {
name: "BoardDiary",
components: { SkeletonImage },
props: {
diary: {
type: Object,
Expand Down Expand Up @@ -58,10 +60,6 @@ export default {
height: 100%;
position: relative;
img {
width: 100%;
height: 100%;
}
.diary-date {
position: absolute;
bottom: 0;
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ WORKDIR /app

COPY package.json .
COPY yarn.lock .
RUN yarn install
RUN yarn install --check-cache --parallel

COPY . .
RUN yarn build
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile-dev
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ WORKDIR /app

COPY package.json .
COPY yarn.lock .
RUN yarn install
RUN yarn install --check-cache --parallel

COPY . .
RUN yarn build:dev
Expand Down
7 changes: 4 additions & 3 deletions plugins/directives.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
// v-lazyload (참고: https://url.kr/l5bxa1)
const lazyloadDirective = {
mounted(el, binding) {
function loadImage(targetElement, imageUrl) {
const imgElement = targetElement;
imgElement.setAttribute("src", imageUrl);
function loadImage(el, imageUrl) {
el.setAttribute("src", imageUrl);
el.onload = () => {};
}

function callIntersectionApi() {
const options = {
root: null,
threshold: 0.5,
rootMargin: "0px",
once: true,
};

const callback = (entries, observer) => {
Expand Down

0 comments on commit f65a587

Please sign in to comment.