If you use Maven, you can the maven-replacer-plugin to automate the 
version/timestamp/build/etc for every build. One could also filter out things 
such unwanted files like .DS_Store with other plugins.

For instance:
     . . .
     <timestamp>${maven.build.timestamp}</timestamp>
     . . .
      <build>
        <plugins>
          <plugin>
            <groupId>com.google.code.maven-replacer-plugin</groupId>
            <artifactId>replacer</artifactId>
            <version>${google.replacer.version}</version>
            <executions>
              <execution>
                <phase>prepare-package</phase>
                <goals>
                  <goal>replace</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <ignoreMissingFile>false</ignoreMissingFile>
              <file>${compiler.output-dir}/index.html</file>
              <replacements>
                <replacement>
                  <token>
                    <![CDATA[<script type="text/javascript" 
src="./App.js"></script>]]>
                  </token>
                  <value>
                    <![CDATA[<script defer type="text/javascript" 
src="./App.js?v=${timestamp}"></script>]]>
                  </value>
                </replacement>
                <replacement>
                  <token>
                    <![CDATA[<link rel="stylesheet" type="text/css" 
href="App.min.css">]]>
                  </token>
                  <value>
                    <![CDATA[<link rel="stylesheet" type="text/css" 
href="App.min.css?v=${timestamp}">]]>
                  </value>
                </replacement>
              </replacements>
            </configuration>
          </plugin>
     . . .

Brian

-----Original Message-----
From: Hugo Ferreira <hferreira...@gmail.com> 
Sent: Thursday, March 9, 2023 4:30 PM
To: dev@royale.apache.org
Subject: [EXTERNAL] Re: Clear the cache strategy

I found this VS Code extension:
https://marketplace.visualstudio.com/items?itemName=adrianwilczynski.terminal-commands
With this I'm writing a script, so then after build-release, right-click on the 
release folder to clean files and inject the version.

Hugo Ferreira <hferreira...@gmail.com> escreveu no dia sexta, 10/03/2023
à(s) 00:05:

> Thank you all.
> You all gave me greate ideas.
> Josh, no need to spend time on this.
> I will create my own script (remove the .DS files is also a good idea 
> - I hate the mac pollute all my folders with that).
>
> Harbs <harbs.li...@gmail.com> escreveu no dia quinta, 9/03/2023 à(s)
> 21:56:
>
>> Yes. My script also has some "aws s3 sync", "aws s3 cp” and "aws 
>> cloudfront create-invalidation” commands to upload the app after 
>> updating the version info.
>>
>> The sync commands (for the whole release directory has these arguments:
>>
>>  --exclude "*.DS_Store*" --delete --cache-control max-age=2592000 
>> --acl public-read
>>
>> The cp command for the index.html file has these arguments:
>>
>>  --metadata-directive REPLACE --cache-control max-age=60,public 
>> --content-type text/html --acl public-read
>>
>>
>> > On Mar 9, 2023, at 11:42 PM, Hugo Ferreira <hferreira...@gmail.com>
>> wrote:
>> >
>> > Thank you.
>> >
>> > OK, after you build-release you run a script that does exactly that.
>> >
>> > Harbs <harbs.li...@gmail.com> escreveu no dia quinta, 9/03/2023 
>> > à(s)
>> 21:37:
>> >
>> >> I have a bash script to stage my app that looks like this:
>> >>
>> >> version=$(cat $DIR/releases.json | jq '.version') 
>> >> version="${version%\"}"
>> >> version="${version#\"}"
>> >>
>> >> build=$(node -e 'console.log(Date.now())') jq '.build = '$build 
>> >> releases.json > tmp.$$.json && mv tmp.$$.json releases.json
>> >>
>> >> sed -ie "s/MyApp.js/MyApp.js?{build_number}/g"
>> bin/js-release/index.html
>> >> sed -ie "s/{build_number}/$build/g" bin/js-release/index.html sed 
>> >> -ie "s/{version_number}/$version/g" bin/js-release/index.html
>> >>
>> >> releases.json has the version and the build number is updated by 
>> >> this script.
>> >>
>> >> The template html has this:
>> >>
>> >>                <meta name="build" content="{build_number}">
>> >>                <meta name="version" content="{version_number}">
>> >>                <link rel="stylesheet" type="text/css"
>> >> href="${application}.css?{build_number}">
>> >>
>> >> The HTML file on the server has a very short TTL. The rest of the 
>> >> files have a much longer TTL. The build script busts the cache 
>> >> when it’s
>> deployed.
>> >>
>> >> Change “MyApp” to the name of your app.
>> >>
>> >> HTH,
>> >> Harbs
>> >>
>> >>
>> >>> On Mar 9, 2023, at 10:43 PM, Hugo Ferreira 
>> >>> <hferreira...@gmail.com>
>> >> wrote:
>> >>>
>> >>> Hi,
>> >>>
>> >>> I'm releasing now updates more often and sometimes (many times), 
>> >>> the browser cache my App.js In a quick google search I found a 
>> >>> solution (more a workaround) =>
>> >>>
>> >>
>> https://stackoverflow.com/questions/1011605/clear-the-cache-in-javasc
>> ript
>> >>> When I build - release with VS Code, it inject this line on my 
>> >>> html file:<script type="text/javascript" src="./App.js"></script> 
>> >>> So, I don't have control over it.
>> >>>
>> >>> What I would like to do is something like have a version flag of 
>> >>> my
>> App
>> >> in
>> >>> the asconfig.json and when I build - relase the compiler inject
>> something
>> >>> like:<script type="text/javascript" src="./App.js?v=1"></script> 
>> >>> <script type="text/javascript" src="./App.js?v=2"></script> ...
>> >>>
>> >>> This is possible today ?
>> >>>
>> >>> Regards,
>> >>> Hugo.
>> >>
>> >>
>>
>>

Reply via email to