问题描述
我想预加载自定义字体。我在Webpack上使用Rails 6。
在config / _fonts.scss中:
@font-face {
font-family: 'customfont';
src: font-url('customfont.eot?81236734');
src: font-url('customfont.eot?81236734#iefix') format('embedded-opentype'),font-url('customfont.woff2?81236734') format('woff2'),font-weight: normal;
font-style: normal;
font-display: swap;
}
我将此字体导入我的应用程序scss中:
@import "config/index";
但是我想预加载该字体。最好的做法是什么?
解决方法
如果我没记错的话,您必须按照本文的规定在视图顶部添加链接标记:https://developer.mozilla.org/en-US/docs/Web/HTML/Preloading_content
然后供href使用who > users.txt
file = open("users.txt","w")
users = file.split("who","where","when").rstrip("\n")
for user in users:
if file.startswith("who"):
print(file.startswith("who") + file.startswith("where") + file.startswith(when_and_IP))
帮助器以指向正确的文件。
还请注意asset_pack_url
必须指向已编译资产所在的文件夹,而不必提及“ public / packs”
那么您可能必须使用类似asset_path_url
之类的东西
(另外,我正在考虑您正在使用Webpack来交付图像/ css和字体。如果您使用的是asdset管道,请使用通常的帮助程序)