-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Improper CSS LINKS !! #5787
Comments
Hello! What behavior are you expecting? Also it seems like the reproduction link doesn't work. |
I sent a new link it should work now [https://stackblitz.com/edit](https://stackblitz.com/edit/withastro-astro-9gn3do good luckj |
Copying over the extra comment from the reproduction for context:
(For the future, it's helpful to include all this information in the issue @louiss0 so someone can get a grasp of things even before opening the Stackblitz.) @louiss0 Is the main issue you are reporting that there is more than one CSS link per page? |
The problem is that the links that are being created are not supposed to be there. A link is supposed to only be created if I import a |
Gotcha. So here’s what I see in <link rel="stylesheet" href="/assets/about.9e97b164.css" />
<link rel="stylesheet" href="/assets/about.635685ef.css" />
<link rel="stylesheet" href="/assets/index.d62cedb6.css" /> It’s not super obvious, but this is expected behaviour. Here’s why:
A couple of questions you may have:
Hopefully that helps explain what’s going on! I’ll close this for now as I don’t think this is a bug, but let me know if I’ve misunderstood the problem. |
This is not a good idea if you do a light house score on this page and you will see that it will complain about render blocking resources https://www.sheltonportfolio.com. The style sheet that it is complaining about is this. https://www.sheltonportfolio.com/assets/404.2f759cc7.css. This is the on that is for my 404 page not for the index page. The problem is that astro is adding stylesheets to pages that have noting to do with each other. |
I guess I wasn’t clear. https://www.sheltonportfolio.com/assets/404.2f759cc7.css is not the CSS for your 404 page. It is CSS shared across all your pages (Tailwind styles by the looks of the contents). The name “404” is just because Astro looks at the list of your pages — just Lighthouse will inform you about render-blocking CSS almost always but that’s not actually usually an issue unless you have huge quantities of CSS you aren’t using (not your case). Instead, check for metrics flagged for improvement. On your site all metrics are green except for Cumulative Layout Shift: You can then filter down audits to only show those relevant to that metric: This will show that CSS is not the key performance issue. Instead the custom font loading and an image without |
It suddenly changed to a 97 I guess the only thing I'd recommend now is that Astro finds a way to indicate to the developer which stylesheet is the main stylesheet. Good luck getting to 2.0 |
It suddenly changed to a 97 I guess the only thing I'd recommend now is that Astro finds a way to indicate to the developer which stylesheet is the main stylesheet. Good luck getting to 2.0 |
I understand I have figured out what was causing most of the layout shift. There are some issues that I could not solve regarding layout shift. But I'm fine. I now wish for a way for Astro to indicate to the developer which CSS file is the main CSS file. Part of the confusion that came from this issue was me not knowing which CSS file was the main one. I hope that could get fixed maybe. Other than that I'm done with this problem I hope I Can now soon use markdoc. |
There isn't really a main CSS file. There are CSS files that are shared throughout the site. Those will create bundles for those shared CSS files. There isn't necessarily 1 of them. They are created to prevent duplication. The alternative is 1 CSS file per page, but that would be duplicating large CSS files like the Tailwind one for each page. Which is also not desirable. There isn't a 1 size fits all approach to CSS bundling that I'm aware of. I'd love to improve how we bundle CSS but I'm not sure what the better way is at the moment. |
Sorry for I'm using closed thread, but I've faced related problem. |
this might be helpful: https://docs.astro.build/en/guides/configuring-astro/#customising-output-filenames import { defineConfig } from 'astro/config'
export default defineConfig({
vite: {
build: {
rollupOptions: {
output: {
entryFileNames: 'entry.[hash].js',
chunkFileNames: 'chunks/chunk.[hash].js',
assetFileNames: 'assets/asset.[hash][extname]',
},
},
},
},
}) |
finally I had to write a magic comment, like |
Hi, I've had this issue and I solved it. So - astro will create separate css files on build which will show up as a chained requests when loading a website that has links to that other website. In my case, the separate css files were due to two different layouts being used on the two pages. Both layout components were loading component and had for content, the only difference was that BaseLayout component had and components, whereas had nothing exceptI solved it like this: I created an EmptyLayout.astro file which had only and basic html stuff inside:
and I used that file for my thank-you page. I then created another component BaseLayout.astro which had navigation and footer inside and used that in my other pages, BUT, I referenced the already-made EmptyLayout.astro like this:
This way, when loading my homepage, tailwind bundled only ONE css file since those two layouts are not considered as two separate pages. |
@stormitornado Could you please provide me with the program code for reference? I also encountered the same problem |
Hi, @Michael0520
and parsed this string in
But I'm confused, is Astro still have this problem? (I've only used it once) |
@stormitornado
|
It will only work, if you manually create css (or scss) file with necessary imports, and add it name in comments. |
I want to fix the style or the name of other resources, |
I just created an integration for this: https://www.npmjs.com/package/astro-generic-build-filenames |
What version of
astro
are you using?1.9.0
Are you using an SSR adapter? If so, which one?
None
What package manager are you using?
pnpm
What operating system are you using?
Windows
Describe the Bug
CSS Files aren't linked in properly. I saw this in my dist folder under index.html when I was looking at the build for my site. Luckily it only cost me a few light house points.
All I did for my app was import the stylesheet that was here.
Then I imported the layout from that file into here.
I imported the base into the 404.html file and thought that the stylesheet had something to do with the bundling problem but that does not seem to be the case. Why is the stylesheet for the 404.html loaded into the index.html page that makes no sense.
The pages have nothing to do with each other and it's costing me performance problems.
Link to Minimal Reproducible Example
https://stackblitz.com/edit/withastro-astro-9gn3do
Participation
The text was updated successfully, but these errors were encountered: