Solved

htaccess file

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

Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

Question has a verified solution.

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

If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
The viewer will learn how to count occurrences of each item in an array.
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 …

832 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