?
Solved

htaccess file

Posted on 2016-08-11
3
Medium Priority
?
115 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 111

Accepted Solution

by:
Ray Paseur earned 1000 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 84

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 1000 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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This Micro Tutorial will demonstrate how nuggets on the Web are formatted by using Chrome Developer Tools. These tools would not only view the site's CSS but it can also modify it and save the CSS to use on your own site.
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 +…
Suggested Courses

762 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