Solved

htaccess file

Posted on 2016-08-11
3
80 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 109

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
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 +…

810 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