jliznaga
jliznaga

Reputation: 11

Handle version of files in AngularJS

I would like to know if exists any way to add a suffix like

'app/account/script.js?v=1.0',
'app/account/style.css?v=1.0',

to all requests in AngularJS, including to css and js files.

Using interceptors we can do something like this Angular template versioning

But unforntunelly that isn't a solution for me.

Thanks

Upvotes: 0

Views: 1860

Answers (1)

jliznaga
jliznaga

Reputation: 11

I solved with this

First in your app.js

app.value('version', '1.0.0');

then we add a new directive

app.directive('disableCache', function(version) {
    return {
        restrict: 'A',
        replace: false,
        link: function(scope, elem, attr) {
            attr.$set("src", attr.src +  "#v=" + version);
        }
    };
});

and we update our html

<script src="scripts/js/filters.js" disable-cache></script>

and will be

<script src="scripts/js/filters.js#v=1.0.0" disable-cache=""></script>

Upvotes: 1

Related Questions