How change revision parameter of CSS and JS files

  • hmm never payed attention to those versions. Do you have any issues with that?

    Thanks for reply... I do not have a problem right now, but they can happen. If I make changes or addition in css/js, it must show up immediately and do not wait for cache expiration (which may be a day /week / month according to server settings). This is however the main reason for using versions parameter.

  • Well I do always make changes and watch them with Firefox. Firefox has been doing a great job with the settings on never to create a history or anything. So on each relead I see the changes, what I never could achieve with Chrome.


    You can as well disable cache in the backend due to developing phase to prevent any caching issues.


    Regards,


    Fossy

  • Well I clear always cache in pagekit backen when I'm sure the changes done how I want. Then it should not impact visitors experience.


    Unfortunately, that's not true. The visitor is still loading css/js files from his browser cache because the filename with parameter is the same. Lifetime of filetypes in cache define nginx or apache settings.

    In the pagekit admin you can clean clean the cache folder but it has nothing to do with browser cache.


    For example, my nginx webserver has this setting:


    Code
    1. location ~ \.(js|css|png|jpg|jpeg|gif|ico|html|woff|ttf|svg|eot|otf)$ {
    2. add_header "Access-Control-Allow-Origin" "*";
    3. expires 30d;
    4. access_log off;
    5. add_header Cache-Control "public";
    6. }


    These files will remain valid for 30 days after caching. Then the browser retrieves the files again.

  • Hmm im running a pagekit installation on nginx server too at work as intranet system and never had this issue tbh. As well tested on many clients and yes I did many customizing on visuals as tested them on several clients after doing them.


    If server not signalizing a change then of course the files will be kept for 30 days but if you clear the cache in pagekit backend it will signalaize to renew the cached files, beside that you can disable the cache in the pagekit backend for developing purpuse.


    Correct me if I'm wrong on that one, but that was my experience with like 9 pagekit installations actually. Well not everyone is on nginx of course. But few are definetly on nginx.


    Regards,


    Fossy

  • https://www.fastcomet.com/tutorials/pagekit/clear-cache


    Well this tutorial tells pretty same as I wrote before, but it's all about staging strategy. My is in general to develop it on local machine or another installation instance and when everything is fine to push it to the public server. Works very smooth especially if you use sql lite installation then it's only files based overwriting.


    if I have access to the ssh session I run then mostly php pagekit migrate and php pagekit clearcache commands in the pagekit installation root folder and this did latest always the trick for me to rebuild cache as well for returning visitors.

  • jhejlik

    Changed the title of the thread from “How change version parameter of CSS and JS files” to “How change revision parameter of CSS and JS files”.
  • Hi @Fossy, thank you for your effort to help me, but my question has not yet been answered:
    How to change the css/js revision parameter or under which conditions revision parameter is changed automaticaly?

    I found the code that adds the revision parameter in the /app/system/src/SystemModule.php file line 23-31. If I comment on it, the revision parameter will be removed.

    PHP: /app/system/src/SystemModule.php
    1. $app->extend('assets', function ($factory) use ($app) {
    2. $secret = $this->config['secret'];
    3. $version = substr(sha1($app['version'] . $secret), 0, 4);
    4. $factory->setVersion($version);
    5. return $factory;
    6. });

    But I'm not a php developer and I cann't find out more from this :(

  • Seems the file version only depends on the version of pagekit (as the secret is created once I think). What you could try is, the create your own extend of the assets and adapt/update the version with properties of your need.


    Have you tried something like this in your module/theme:

    Code
    1. $app->extend('assets', function ($factory) use ($app) {
    2. $version = sha1(someCustomArgument)
    3. });

    Did not test that, but could work.

    The LORD is my strength and my shield; in him my heart trusts, and I am helped; my heart exults, and with my song I give thanks to him. Psalm 28,7

  • Hi SAB , thanks for the tip, I'll try it. But I'm afraid it is over my programming skills.

    I think it would be better separate extension rather than integration into the template. A fully working versioning system is today one of the basic needs of a webdesigner for website modifying in a production environment.