Solved

htaccess file

Posted on 2016-08-11
3
103 Views
Last Modified: 2016-08-24
I have asked this question before but it was for a windows server.  What / how do you write an entry in the .htaccess file to leverage the browser cache?  I want to add images, javascript and css to the browser cache
0
Comment
Question by:rgranlund
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 57

Expert Comment

by:giltjr
ID: 41752977
What the browser caches is based on how the browser is configured.

If a browser is configured to cache (the default) it should already cache all the files you listed.

For html files, a server can influence if a page is not cached, or how long it is cached for.  It can not force a browser to cache something if the browser is setup to not to cache.

For non-html files (javascript, images, css) you can't control anything dealing with caching on the browser side.  Either the browser is configured to cache or not to cache.
0
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 250 total points
ID: 41753002
There are some tricks that you can use to prevent  caching on the browser, such as manipulating GET arguments on the CSS and JS links, but not much you can do to cause  it, except produce headers with long-future expiration dates.  Most browsers will cache whatever they can.  I go to lengths to turn the browser cache off, because I'm almost constantly developing and I always want to see the latest version of my CSS and JavaScript files.

You can induce caching on the server (where nearly everything is under your control).  This article shows the design pattern.
https://www.experts-exchange.com/articles/18437/Improving-Web-Site-Performance-via-PHP-Cache.html
1
 
LVL 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 250 total points
ID: 41753035
This page https://www.howtoforge.com/make-browsers-cache-static-files-with-mod_expires-on-apache2-debian-squeeze gives examples of how to lengthen the time that is requested for files to expire in the browser cache.  The theory is that keeping files in the browser cache longer speeds up loading the page.

But I'm with Ray on this, I never do it because even the normal browser cache causes problems in development.  If you are still working on the site, I have to recommend that you do not do this.
0

Featured Post

Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
How to create a custom search shortcut to site-search Experts Exchange using Google in the Firefox browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch your Bookmark Menu: Press 'Ctrl +…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question