Full refactor for allowing chained cache busting

Calculating hash of the file is now executed after references have been
updated (instead of before). This way changes in one file get
propagated to the root file which shouldn’t be cached. Previous version
would only update own file name and not the entire chain.