Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何将字体和图像(一般资产)转换为数据属性?
以这种方式加载资产会更快还是更慢?
您应该知道,早于 IE8 的 IE 不支持 DataURI。此外,IE8 对 css 资产中最多 32KB 的 dataURI 有限制。可以在此博客文章中找到有关 DataURI 的更详细说明。
如果您需要 java 实现,可以在这里找到:
这允许您将所有图像转换为 css 文件中的 base64 编码 uri。有关如何将此实现集成到您的项目中的更多详细信息,请访问此页面:
披露:我隶属于 wro4j 项目。
您的页面加载速度会变慢,因为每个请求都必须下载数据,而可以缓存单独的文件。尝试仅将数据 uri 用于小文件。
用于图像的 uri 编码器:http ://www.scalora.org/projects/uriencoder/
您可以使用FileSystem API的readAsDataURL肉类。但它目前仅适用于 chrome。
readAsDataURL