Search code examples
httpcache-control

Using Cache-Control in HTTP per Element


I am using only HTTP and set "meta http-equiv="Cache-control" content="public"" in my head. How can I set the max-age of an element? Do I need to wrap it in a certain tag or would I use an attribute? I would like to set the max-age of my css and js sources to a certain max age.


Solution

  • Every resource being loaded is a separate request. If you want to control the caching of your JS and CSS files, you'll have to set the appropriate headers for those requests. Your web server should have a way to do that - if not, you'll just have to write your own handlers to add the headers as needed.

    There is nothing you can do in HTML to achieve this, short of inlining the files.