Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【图片加载】优化图片加载的速度,适配移动端小屏幕 #2372

Closed
zscmmm opened this issue May 3, 2024 · 2 comments · Fixed by #2411
Closed

【图片加载】优化图片加载的速度,适配移动端小屏幕 #2372

zscmmm opened this issue May 3, 2024 · 2 comments · Fixed by #2411
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@zscmmm
Copy link

zscmmm commented May 3, 2024

为什么提出这个新的特性改动
本来网速就慢了, 如果图片加载原图那就更慢了, 我简单的试了一下, 无论是手机还是电脑, 加载的图片大小都是固定的, 能否实现根据页面的大小来自动调节加载图片的大小, 比如手机屏幕尺寸本来就小, 加载出的图片大小还是 config.js 中设置的大小, 这对于网速的影响还是有的. 要是可以根据页面来自动加载图片的大小就好了

  • 下面是手机访问
图片
  • 下面是电脑访问
图片

描述一下你推荐的解决方案
无, (PS: 对这个就不是很懂了, 其实可以简单的预设几种图片加载的大小的方案,比如大中小三种方案, 根据检测网页或者标签的大小, 自动选择预设的图片的大小 , 然后返回)

描述一下你考虑过的其它替代解决方案
无,

补充说明
无, 如问题描述

@zscmmm zscmmm added the enhancement New feature or request label May 3, 2024
@tangly1024 tangly1024 changed the title 优化图片加载的速度 【图片加载】优化图片加载的速度 May 6, 2024
@WillWang2122
Copy link

@tangly1024 我想,我在wordpress 上的做法,不知道在notionnext 上有沒有辦法直接移植,在wordpress 上加載要快我是把image 和其他的一些assets (像JS CSS 檔等靜態的assets) offload 到AWS S3 之類的對像儲存設備中,並設定好CDN,訪問時用rewrite rule把OSS 上取得assets... 在wordpress 有很多插件可以做到,如wp offload media/ keyCDN/ super cache/ wp rocket... 之類的
node framework我不懂,要看看大佬們有沒有解決方案~

@tangly1024
Copy link
Owner

tangly1024 commented May 14, 2024

可以处理

通过识别浏览器宽度,给与用户一个合适的图片尺寸。
目前全站的图片尺寸在blog.config.js 中由配置统一决定,默认是800.
只需要通过js监听用户浏览器尺寸、并对url中的参数并进行替换即可。

Notion文件上传

Notion图片上传使用的是aws对象存储,其支持通过url指定参数来获取不同尺寸的参数;
例如一张图片url如下:
https://www.notion.so/image/xx.xxx&width=800&cache=v2

其中的 width=800 就是图片宽度,修改此值即可实现图片尺寸的替换。替换成 width=300 就能获取更小的图片

Notion内置第三方图片源

除此之外,notion内置的第三方图片服务例如 upsplash。
image

它也支持图片参数请求,以下图片url中的width是800;
https://images.unsplash.com/photo-1671726203449-34e89df45211?ixlib=rb-4.0.3&q=50&fm=webp&crop=entropy&cs=srgb&t=db0e0da3-a27e-445c-9f69-9c95b33a52bc&width=800&fmt=webp

image

替换url中的宽度为100后如下效果
``https://images.unsplash.com/photo-1671726203449-34e89df45211?ixlib=rb-4.0.3&q=50&fm=webp&crop=entropy&cs=srgb&t=db0e0da3-a27e-445c-9f69-9c95b33a52bc&width=100&fmt=webp`

image

实际尺寸的考量方案

我想为了最好的体验,可以这样做:

  1. 设置一个尺寸最大值为800;在任何尺寸下图片不应大于此值,否则影响加载效率。
  2. 小屏下检测屏幕尺寸,将屏幕的最大宽度设置为图片宽度,例如屏幕宽度400,则统一修改图片宽度为400,下不设限。

@tangly1024 tangly1024 added the documentation Improvements or additions to documentation label May 14, 2024
@tangly1024 tangly1024 changed the title 【图片加载】优化图片加载的速度 【图片加载】优化图片加载的速度,适配移动端小屏幕 May 14, 2024
@tangly1024 tangly1024 added good first issue Good for newcomers and removed documentation Improvements or additions to documentation labels May 14, 2024
@tangly1024 tangly1024 linked a pull request May 14, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants