Solved

htaccess file

Posted on 2016-08-11
3
66 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
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 108

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 82

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

#Citrix #Internet Explorer #Enterprise Mode #IE 11 #IE 8
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This video teaches users how to migrate an existing Wordpress website to a new domain.
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.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now