Question: I made a change on one of the `.js` files that I use and no matter what I do, flask insists on picking up, from memory cache, the last version of the file, without the change.

To clarify, I have the following structure. It all starts with `foo.html`

```
return render_template foo.html

```

`foo.html` has a form inside that calls flask with some data and then returns a second template `bar.html`:

```
return render_template bar.html

```

This second template calls some `.js` file, placed in the `static` folder, but it doesn't update when the code changes.

I mention the structure above because if the `.js` file was placed on `foo.html` instead of `bar.html` then Flask **would** pick up the new changes on the file. But in `bar.html` Flask completely ignores them.

What is happening? 

The only thing that worked was to click on "disable cache" on the browser and reload again.

Answer: 
Caching is *normally good*, so it's not advisable to eliminate it entirely. And using `control` + `F5` or whatever to do a hard refresh is obviously not a scalable solution since you have to do it in every browser on every computer. 

A better idea is to **let browsers cache the files most of the time, but not right after they've been updated.** You can achieve this by appending the time that the source file was last updated as an argument to its path URL. For simplicity, you can use the most recent modification time for any file in the static folder (or any subfolders), as opposed to looking at each file individually.

Python
------

```
def dir_last_updated(folder):
    return str(max(os.path.getmtime(os.path.join(root_path, f))
                   for root_path, dirs, files in os.walk(folder)
                   for f in files))

@app.route('/my-site')
def my_site():
    return render_template('my-site.html',
                           last_updated=dir_last_updated('mydir/static'))

```

Jinja Template
--------------

```
<script type="text/javascript" src="/static/my-script.js?u={{ last_updated }}"></script>

```

HTML Result
-----------

```
<script type="text/javascript" src="/static/my-script.js?u=1547330602.31"></script>

```
USE CTRL+ f5 to refresh the browser