我在S3插件上配置了阿里云 OSS ,启用了图片压缩功能,但并没有针对 SVG 配置压缩。
在 页面的调试信息中,看到 SVG 图片的 img 标签被自动加上了 srcset,里面包含了多个带 x-oss-process=image/resize 的变体链接(例如 w_1600、w_1200、w_800、w_400,都带 m_lfit),同时还带有 data-src、sizes、style="filter: invert(0)" 等属性。
我使用markdown进行编辑,图片的引用是这样的:
。
预览没有问题。
AI给出的建议是注入下面的代码,确实有效:
<script>
document.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll('img').forEach(img => {
const u = img.getAttribute('data-src') img.src '';
if (u.split('?')[0].toLowerCase().endsWith('.svg')) {
img.removeAttribute('srcset');
img.removeAttribute('sizes');
}
});
});
</script>
看了下更新可能是响应式图片有关,所以想问下如何正确解决这个问题。