CloudFront 提供的 CSS 文件未呈现

发布于 2024-12-08 00:32:37 字数 485 浏览 1 评论 0原文

这是一个奇怪的问题,但我认为我在某个地方做了一些愚蠢的事情,最终导致了目前的情况。

当尝试从 CloudFront 提供静态文件(图像、css 和 js)时,它们似乎无法正确呈现。例如,我的样式表之一可以在这里找到: http://d21uvxjmc903qz.cloudfront.net/stylesheets/hf.4fabc9c719f8 .css,但它似乎没有“应用”到正如我所期望的 DOM。 (例如,在 Firebug 中的 Chrome 或 Firefox 中的开发人员工具中查看相关样式未应用于

元素。

查看响应标头,它看起来像 Content -Type 设置正确,所以我几乎没有关于

下一步该看什么的建议?

This is an odd issue, but I assume I've done something boneheaded somewhere along the line to end up with this current situation.

When trying to serve static files (images, css & js) from CloudFront, they don't seem to be rendering properly. For example, one of my stylesheets is available here: http://d21uvxjmc903qz.cloudfront.net/stylesheets/hf.4fabc9c719f8.css, but it doesn't seem to be "applied" to the DOM as I would expect. (For example, looking in developer tools in Chrome or Firefox in Firebug the relevant styles aren't applied to the <header> element.

Looking at the response headers, it looks like the Content-Type is set properly, so I'm pretty much out of ideas.

Any suggestions on where to look next?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

勿挽旧人 2024-12-15 00:32:37

问题可能是 S3 存储桶中的内容类型错误。我遇到了同样的问题,更改内容类型解决了问题。我将下面的内容从 text/plain 更改为 text/css,然后样式呈现正确。

在此处输入图像描述

The problem is likely the wrong content-type in the S3 bucket. I had the same trouble, and changing the content-type fixed the issue. I changed the below from text/plain to text/css and then the styles rendered correctly.

enter image description here

那些过往 2024-12-15 00:32:37

对我来说,链接不能是 http,而必须是 https://..
其修改为以下内容时,它对我有用

<link rel="stylesheet" href="w3.css">

当我在 html 文件中将

希望有帮助。

For me the link couldn't be http but had to be https://..
It worked for me when i modified this

<link rel="stylesheet" href="w3.css">

in the html file to this:

<link rel="stylesheet" href="https://s3.amazonaws.com/yourFolder/w3.css">

hope that helps.

红衣飘飘貌似仙 2024-12-15 00:32:37

我知道这是一个非常老的问题,但我找到了一个适合我解决同样问题的解决方案:在CloudFront控制台中,我为 /* 创建了一个新的“无效”,据我所知,它强制请求静态文件转到源而不是 CloudFront 缓存,这解决了我的 css 渲染问题,因为我最近更改了项目中 css 文件的位置。

I know this is a super old question but I found a solution that worked for me with the same problem: in the CloudFront console, I created a new 'invalidation' for /* which as I understand it forces requests for the static files to go to the origin instead of the CloudFront cache, and this fixed my css rendering issues as I had recently changed the location of css files in my project.

淡淡的优雅 2024-12-15 00:32:37

刚刚从 cloudfront 提供的 CSS 文件出现问题,我们认为该文件未正确提供。问题最终是背景的 url 值中存在未转义的单引号。

background: url(//xxxxx.cloudfront.net/img/flags48/Cote%20d'Ivoire.png) no-repeat}

' 替换为 %27 后,CSS 问题就得到了解决。

background: url(//xxxxx.cloudfront.net/img/flags48/Cote%20d%27Ivoire.png) no-repeat}

Just had an issue with a CSS file served from cloudfront that we thought was not served correctly. The issue ended up being an unescaped single quote inside of a backgroud's url value.

background: url(//xxxxx.cloudfront.net/img/flags48/Cote%20d'Ivoire.png) no-repeat}

Once we replaced ' with %27, the CSS issues were fixed.

background: url(//xxxxx.cloudfront.net/img/flags48/Cote%20d%27Ivoire.png) no-repeat}
妖妓 2024-12-15 00:32:37

我正在使用 Hugo 来渲染我的网站。我发现我需要在baseURL的值中指定HTTPS协议,而不仅仅是路径。

例如,在文件 config.toml 中:

baseURL = https://example.com

或在命令行上,

hugo --baseURL https://example.com

向 @pascati 致谢并 +1,他引导我找到了这个 Hugo 解决方案。

I am using Hugo to render my website. I found that I need to specify the HTTPS protocol in the value of baseURL, not just the path.

For example, in file config.toml:

baseURL = https://example.com

or on the command line,

hugo --baseURL https://example.com

A tip of the hat and +1 to @pascati, who led me to this Hugo solution.

爱的那么颓废 2024-12-15 00:32:37

我在使用 s3cmd 将本地文件与 S3 同步时遇到了这个问题。 s3cmd 客户端对 .css 文件的 MIME 类型进行假设,并返回 Content-Type: text/plain

我使用以下命令标志和 s3cmd 修复了此问题:

--no-mime-magic

还有各种其他相关选项 - 请参阅 https://s3tools.org/usage 了解更多信息。

您可能需要先使 Cloudfront 边缘缓存失效(并从 S3 中删除文件,然后再次同步),然后才能看到此效果。

I ran into this problem when using s3cmd to synchronise my local files with S3. The s3cmd client makes an assumption about the MIME type of the .css file and it returns with Content-Type: text/plain.

I fixed this using the following command flag with s3cmd:

--no-mime-magic

There are various other associated options - see https://s3tools.org/usage for more info.

You may need to invalidate your Cloudfront edge cache (and remove the file from S3 then sync again) before you can see this take effect.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文