Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7488347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T14:50:35+00:00 2026-05-29T14:50:35+00:00

Say I for some reason want to serve my CSS through PHP (because of

  • 0

Say I for some reason want to serve my CSS through PHP (because of pre-processing, merging, etc). What do I need to do in my PHP to make this work well? Other than the most obvious:

header('content-type: text/css; charset=utf-8');

What about headers related to caching, modification times, etags, etc? Which ones should I use, why and how? How would I parse incoming headers and respond appropriately (304 Not Modified for example)?


Note: I know this can be tricky and that it would be a lot easier to just do what I want to do with the CSS before I deploy it as a regular CSS file. If I wanted to do it that way, I wouldn’t have asked this question. I’m curious to how to do this properly and would like to know. What I do or could do beforehand with the CSS is irrelevant; I just want to know how to serve it properly 🙂

Note 2: I really would like to know how to do this properly. I feel most of the activity on this question has turned into me defending why I would want to do this, rather than getting answers on how to do this. Would very much appreciate it if someone could answer my question rather than just suggesting things like SASS. I’m sure it’s awesome, and I might try it out sometime, but that’s not what I’m asking about now. I want to know how to serve CSS through PHP and learn how to deal with the caching and things like that properly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T14:50:37+00:00Added an answer on May 29, 2026 at 2:50 pm

    A commendable effort. Caching gets way too little good will. Please enjoy my short prose attempting to help you on your way.

    The summary

    Sending an ETag and a Last-Modified header will enable the browser to send a If-Modified-Since and a If-None-Match header back to your server on subsequent requests. You may then, when applicable, respond with a 304 Not Modified HTTP status code and an empty body, i.e. Content-Length: 0. Including a Expires header will help you to serve fresh content one day when the content has indeed changed.

    The apprentice

    Sounds simple enough, but it can be a bit tricky to get just right. Luckily for us all, there is really good guidance available.

    Once you get it up and running, please turn to REDbot to help you smooth out any rough corners you may have left in.

    The expert

    For the value of the ETag, you will want to have something you can reproduce, but will still change whenever the content does. Otherwise you will not be able to tell whether the incoming value matches or not. A good candidate for a reproducible value which still changes when the content does, is an MD5 hash of the mtime of the file being served through the cache. In your case, it would probably be a sum for all the files being merged.

    For Last-Modified the logical answer is the actual mtime of the file being served. Why neglect the obvious. Or for a group of files, as in your case, use the most recent mtime in the bunch.

    For Expires, simply choose an appropriate TTL, or time-to-live, for the asset. Add this number to the asset’s mtime, or the value you chose for Last-Modified, and you have your answer.

    You may also want to include Cache-Control headers to let possible proxies on the way know how to properly serve their clients.

    The scholar

    For a more concrete response to your question, please refer to these questions predating yours:

    • What headers do I want to send together with a 304 response?
    • Get Browser to send both If-None-Match and If-Modified-Since
    • HTTP if-none-match and if-modified-since and 304 clarification in PHP
    • Is my implementation of HTTP Conditional Get answers in PHP is OK?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say that for some reason you need to write a macro: MACRO(X,Y) .
Say I need some very special multiplication operator. It may be implemented in following
Say I have some 10 categories that I need to reference in a web
To clarify: I'm not using the gettext php module /extension, reason being because I
I want my search field to say Where are you make it disappear when
Say I want to make a statistic page over working hours in a company.
I have an ASP.NET web service which does some heavy lifting, like say,some file
with agile estimating, is it true some say to choose intervals like 1/2 to
I'm totally confused on this matter, some say use tables and others say it's
Say I have some code like namespace Portal { public class Author { public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.