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 6145467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:47:49+00:00 2026-05-23T18:47:49+00:00

I need to set some HTTP headers Expires, Cache-Control, Last-Modified, for resources as CSS

  • 0

I need to set some HTTP headers “Expires”, “Cache-Control”,
“Last-Modified”, for resources as CSS files, Images files, js files,
etc (Webroot content).

I’ve read that there’s some functionality, through

   Configure::write('Asset.timestamp', true); // In core.php

and the assetTimestamp method of the Helper class.

Now, the question is: How is it used?

I read the HtmlHelper code and in the css method, line 361 there’s this:

$url = $this->assetTimestamp($this->webroot($path));
  • 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-23T18:47:50+00:00Added an answer on May 23, 2026 at 6:47 pm

    Solved.

    First of all you have to consider to make it through Apache. You can take a look at this guide:
    http://httpd.apache.org/docs/2.2/caching.html

    The thing is that CakePHP has a method to do this. And is pretty good.

    I’ll explain this for CSS files. Of course can be used to JS content as well.

    1) In your core.php file (under app/config/) uncomment this line:

    Configure::write('Asset.filter.css', 'css.php');
    

    That line says to CakePHP to route all requests to CSS files through that “css.php” script. As the name implies, it’s a filter. There we can do whatever we want.

    2) Create that “css.php” file. You’ve to create it under app/webroot/

    Make there, you can take the file that the browsen is requesting and apply some cache HTTP headers.

    Something like:

    $filepath = CSS . $regs[1]; //There are some variables that are can be used in this script, take a look to de docs.
    
    $output = file_get_contents($filepath);
    header("Date: " . date("D, j M Y G:i:s ", $templateModified) . 'GMT');
    header("Content-Type: text/css");
    header("Expires: " . gmdate("D, d M Y H:i:s", time() + DAY) . " GMT"); //WEEK or MONTH are valid as well
    header("Cache-Control: max-age=86400, must-revalidate"); // HTTP/1.1
    header("Pragma: cache");        // HTTP/1.0
    print $output;
    

    That’s it! There your content will be served with those headers specified and the browser will know that can cache them.

    Take a look at:

    http://www.bunchacode.com/programming/get-cakephp-build-in-css-compression-to-work/

    There’s a good version of css.php that also minfies it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I display set of images(small). I need to show the larger image(300*300) at some
I need some help with a CSS layout. It is set up like this:
Some web servers return content-length set to zero in the HTTP response headers. I'd
I need to set some server specific variables in a rails application that will
I need to set up some RewriteRules to redirect a URL which has a
I need to set up some SET options in Oracle SQLplus command line program
I need to set the height of every textbox on my form, some of
here is some code I've been working on, basically I need to set up
I have a page with some HTML in it. and I need to set
I need to do some REST service testing from Firefox where I set the

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.