-1

Is there any reason why I'd be getting a 404 error from a CSS file with a version number on the end of it?

<link rel="stylesheet" href="styles/main.css?v=123">

My file is also named main.css?v=123.

Any help is appreciated. Thanks in advance!

6
  • 2
    That's not how it's supposed to work. Don't add the parameters to the file, just call it main.css. Commented Nov 19, 2015 at 20:17
  • @Juhana Huh. I'm confused...? Commented Nov 19, 2015 at 20:20
  • 5
    If your file is really called "main.css?v=123", you're doing it wrong. Call it just "main.css". The whole point is that when you update the file you don't have to change its name, you just change the version number in the HTML only. Commented Nov 19, 2015 at 20:22
  • @Juhana This was so my users get my most recent stylesheet instead of some cached version. Do I need the version anywhere else? In my CSS file, perhaps? Commented Nov 19, 2015 at 20:24
  • 1
    I don't know how to say it any more clear. Leave the HTML as it is now, and name the CSS file "main.css". Then it'll work as you want it to. Commented Nov 19, 2015 at 20:26

3 Answers 3

2

You should rename your file to just main.css, then in the html reference it like this: <link rel="stylesheet" href="styles/main.css?v=123">

You'll only need to change the version in the HTML after you've updated your css. Remember, your css file will always be named just main.css

Hope that helps!

Sign up to request clarification or add additional context in comments.

Comments

1

Just to clarify this is called querystring caching. You add the querystring in the HTML only. When you change it most browsers will assume it's a new file and reload it regardless of how you set the cache for CSS files.

It's possible to do this via PHP without having to manually change it every time you change the css file.

<link rel="stylesheet" href="styles/main.css?t=<?php echo filemtime( 'styles/main.css'); ?>" type="text/css" media="screen" />

This appends the css files modification time to the HTML. Every time you save the CSS file this will update automatically.

Comments

1

By this type of link, you passed to browser the HTTP request GET, with argument v and its value 123. Server is still looking for main.css. The 404 code means page not found.

If you want to server handles it use URL-rewriting. Or you can try encode the question mark by typing %3F.

Please note that file names containing question marks aren't allowed on windows and MSDOS systems.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.