I have found a workaround. I feel is a hackish solution, but it fixed my problem.
My idea was to create a Windows Service that will do a request every couple of seconds to make sure IIS will always consider my JavaScript files as frequent hits and to always have a compress version of them:
class JsScriptCompressKeeper
{
private bool keepRunning = true;
public void Start()
{
var thread = new Thread(Run);
thread.Start();
}
public void Stop()
{
keepRunning = false;
}
public void Run()
{
var mainUrl = "www.example.com";
var pingTimeout = 7; //seconds
// my js filenames are like babel-polyfill.asd123eqwed.js and main.113edweq.js
var patterns = new[] { @"babel-polyfill.([A-Za-z0-9\-]+).js", @"main.([A-Za-z0-9\-]+).js"};
using (var client = new WebClient())
{
// parse the HTML and find my JS files
var mainHtml = client.DownloadString(new Uri(mainUrl));
var urls = patterns.Select(pattern =>
{
var match = Regex.Match(mainHtml, pattern);
var fileName = match.Groups[0].Value;
return new Uri($"{mainUrl}/{fileName}");
}).ToList();
while (true)
{
if (!keepRunning)
{
break;
}
Thread.Sleep(TimeSpan.FromSeconds(pingTimeout));
urls.ForEach(url =>
{
client.DownloadString(url);
});
}
}
}
}
P.S. I feel my solutions is too hackish, so I will not accept my answer. Maybe someone else has a cleaner solution! :)