2

I have an application built in zf2, all the js, css, images are in the public directory. The js and css files which are needed in all the phtml files are declared in layout.phtml of Application module.

echo $this->headLink (  )
              ->prependStylesheet ( $this->basePath () . '/css/owl.carousel.css' )
              ->prependStylesheet ( $this->basePath () . '/css/owl.theme.css' );

<script type="text/javascript" src="/js/layout.js"></script>         
<script type="text/javascript" src="/assets/bootstrap-fileupload/bootstrap-fileupload.js"></script>
<script src="/js/custom.js"></script>

And The files that are needed for a particular phtml file I include them in that file directly. I am using caching to cache images. But the problem here is that whenever I made some changes in my js or css files I have use ctrl+f5 to see the changes otherwise they are not reflected. Below are the configurations of my .htaccess file:

# Enable expirations
ExpiresActive On

# My favicon
ExpiresByType image/x-icon "access plus 1 year�

# Images
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"

As you can see I have configured htaccess to cache only images but browser is caching js and css file automatically. I can do ctrl f5 but how can I tell my user to ctrl f5. On some searching I came accross asset management. I am thinking to follow this one Assetic Module. I have some doubts like how to use it to include js or css files in different phtml file? How much changes are needed to use it in existing ZF2 application ? Or Someone with better options ? If anyone who have implemented this earlier then please share some code snippets.

iit2011081
  • 742
  • 8
  • 26

1 Answers1

1

This has nothing to do with your .htacces nor the implementation of the assets.

Browsers just cache css and js files if they can. There plenty of ways to force a "refresh" or just serving new files which you can find here How to force browser to reload cached CSS/JS files?

I however would not recommend messing with this unless you really have to since browsers actually do cache this for a reason.

Community
  • 1
  • 1
cptnk
  • 2,430
  • 18
  • 29
  • Thanks for the clarification .I want caching of js, css files but when I make any change in any file then user should have the latest changes. After following the link which you posted I came to know that this can be done in two ways one by adding some query string to the file url and another is google PageSpeed plugin. If you have used any of them them help me to find out which one is better ? – iit2011081 Jun 14 '16 at 19:45
  • I personally used the Simple Client-side Technique. It's the easiest imo. And you can somewhat create a versioning for either your js/css or just keep it creating versions so no one ever caches your css/js. – cptnk Jun 15 '16 at 03:12