Skip to content

Commit

Permalink
feat(Post): cancel image HTTP request when unloading
Browse files Browse the repository at this point in the history
  • Loading branch information
AlejandroAkbal committed Jul 29, 2022
1 parent cc50b9c commit d30d5ec
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions components/pages/posts/post/Post.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
>
<img
:key="mediaFile[0].url"
ref="imageElement"
:alt="'Image ' + post.data.id"
:class="{
'opacity-100': media.hasLoaded,
Expand Down Expand Up @@ -458,6 +459,19 @@ export default {
}
},
beforeDestroy() {
// Cancel any pending HTTP requests
if (this.isImage) {
const imageElement = this.$refs['imageElement']
if (imageElement) {
// TODO: This trick only works in Chrome
imageElement.src = 'data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='
imageElement.onload = null
imageElement.onerror = null
}
}
},
Expand Down

0 comments on commit d30d5ec

Please sign in to comment.