Question: When I am ready to publish my code changes to our server, I build and compile using Angular AOT and copy my files over. Sometimes end users aren't getting these changes and have to do a hard refresh, or go into their browser history and clear cached images and files. What is the recommended method of forcing a hard refresh when I make changes to code on the server?

I've read about appending a version number to .css and .js files so the browser re-downloads the newly named files, but with angular AOT creating ngfactory.js files and ngfactory.js.map files, etc, I want to make sure I am doing this properly.

Also, I am hosting the site using IIS so if there is a way to achieve refreshing through ISS I am open to that as well.

Answer: 
The suggested algorithm by the OP may have a problem, even though it works on a limited range of numbers from 2 to 10 to produce the expected results of `2,3,5,7` after correcting the code. Unfortunately, if the range of numbers is enlarged, then 
non-prime numbers can creep in, as demonstrated below: 

```js
var arr = [2];

function myFunction() {

    for (i = 3; i <= 30; i++) {
        if (i % 2 !==0 && i % Math.sqrt(i) !==0) {
            for (j = 0; j <= arr.length - 1; j++){
                if (i % arr[j] !== 0) {
                    arr.push(i);
                }
                break;
            }
        }
    }
    document.getElementById("demo").innerHTML = arr;
}  
myFunction();
```

```html
<div id="demo"></div>
```

The following code may be less efficient but the upside is that it works no matter how large the range of numbers. The solution derives from code borrowed and modified from [here](http://studymaths.co.uk/topics/checkIfPrime.php) and [here](https://webcache.googleusercontent.com/search?q=cache:FUm5e7Q9x-8J:https://www.thepolyglotdeveloper.com/2015/04/determine-if-a-number-is-prime-using-javascript/%20&cd=1&hl=en&ct=clnk&gl=us).

```js
var arr = [2];

function isPrime( n ) {

   // eliminate non-integers 
   if (  n != Math.round(n)  ) {
      return false;
   }

   // assume n is prime and test if true
   for(var i=2, max=Math.sqrt(n); i <= max; i++) {
       if ( n % i === 0 ) {
           return false;
       }
    }
    return n > 1;
}

function myFunction() {

    for (i = 3; i <= 30; i++) {
      if ( isPrime(i) ) {
          arr.push(i); 
      }// end-if
    }// end-for
    document.getElementById("demo").innerHTML = arr;
}

myFunction();
```

```html
<div id="demo"></div>
```

Note, the array starts initially with prime number 2 and as the code encounters prime numbers within the specified range they are added to the array. Incidentally, you need an HTML DIV tag with an id of "demo" for this to work. And, you only need to assign the array to the innerHTML property of the div element once, after the loop has finished processing. Lastly, you need to call myFunction().

Interesting related discussion [here](https://stackoverflow.com/questions/1801391/what-is-the-best-algorithm-for-checking-if-a-number-is-prime).
```
function primeNumbers(num){
  let primeNum=[2];

  for (let i=3;i<=num;i++){
    let notPrime=[];
    for (let j=2;j<i;j++){
      if (i%j===0){
        notPrime.push(i);
      }
      if (notPrime.length===0){
        primeNum.push(i);
      }
    }
  }
  return primeNum;
}
primeNumbers(10);

```