2

using SeedStack 14.7 we are facing a cache issue when uploading a new version on servers: every user have to clear their cache to get the last version of files.

I tried to use "urlArgs": "version=2" in the requireConfig part of the fragment JSON file. It do the job by adding argument on every files and so we can use it when changing version, but it also affect the urls in the config of each modules !

As we are using this config to pass the REST base url to each module, it breaks all REST requests by adding the argument to the base url.

My fragment JSON file :

{
    "id": "mac2-portail",
    "modules": {
        "gestionImage": {
            "path": "{mac2-portail}/modules/gestionImage",
            "autoload": true,
            "config": {
                "apiUrl": "muserver/rest"
            }
        }
    },
    "i18n": {...},
    "routes": {...},
    "requireConfig": {
        "urlArgs": "version=2",
        "shim": {...}
    }
}

Any idea to solve the cache issue without breaking REST requests ?

EDIT : it is not a duplicate of Prevent RequireJS from Caching Required Scripts. Yes SeedStack uses RequireJS and this configuration solve the cache issue, but it also affect other modules defined in the fragment so I need to find another solution to prevent browser to cache files

Community
  • 1
  • 1
Finrod
  • 2,425
  • 4
  • 28
  • 38
  • Can someone add the "seedstack" tag for me ? I do not have enough reputation to create it, but I probably need it for the SeedStack team to be alerted of my question – Finrod Aug 19 '15 at 09:31

1 Answers1

3

The module configuration values, like apiUrl in your example, are not touched by RequireJS unless you call require.toUrl() on them explicitly. I think this is what is happening in your case. To avoid this problem, you should always do the concatenation first and only then call require.toUrl() on the full resulting URL.

So, instead of doing:

var fullUrl = require.toUrl(config.apiUrl) + '/my/resource';

Do this:

var fullUrl = require.toUrl(config.apiUrl + '/my/resource');

By the way, instead of setting the version directly in the RequireJS configuration, you can simply add the version of your application to the data-w20-app-version attribute on the <html> element of the master page:

<html data-w20-app data-w20-app-version="2.0.0">

This will provide the same behavior but will work correctly in the case of Angular templates in $templateCache. If your master page is automatically generated by the backend, this is done automatically. Check this page for the details.

Adrien LAUER
  • 444
  • 2
  • 7
  • Thanks for the answer Adrien, we are using a generated masterpage, but I don't see any data-w20-app-version in the HTML tag. Is this functionnality coded in version 14.7 ? If not, I will check if we can update our SeedStack version or change all our require.toURL() calls (you are right, we are doing it before concatenation). – Finrod Sep 08 '15 at 08:12
  • This tag was effectively added after the 14.7 version. Note that we can only discuss about the Open-Source version on StackOverflow. Anyway, whatever the version, you must update the way you do URL concatenation if you want it to work properly. – Adrien LAUER Sep 08 '15 at 10:16
  • Thanks Adrien, we will update our URL concatenation. – Finrod Sep 08 '15 at 11:58