简体   繁体   English

如何使用angular将时间戳添加到index.html中的src标签

[英]How to add timestamp to tag src in index.html using angular

I am using angular 1 to develop an application I want to add a argument to my scripts, so the browser detecte a change and load them for second time. 我正在使用angular 1开发应用程序,我想在脚本中添加一个参数,因此浏览器会检测到更改并将其第二次加载。 Because of the cache, changes are not token in consideration by the browser 由于具有缓存,浏览器不会考虑更改

Here is my index file: 这是我的索引文件:

<html lang="fr" ng-app="app" class="no-js">
<!--<![endif]-->
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>Test</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width">

    <link rel="icon" href="assets/img/favicon.ico" type="image/x-icon" />

    <link rel="stylesheet" href="css/bootstrap.flatly.min.css">
    <link rel="stylesheet" href="css/main.css">
    <link rel="stylesheet" href="fonts/font-awesome/css/font-awesome.css">
    <link rel="stylesheet" href="css/main_sejour.css">
    <link rel="stylesheet" href="css/normalize.css">

    <script src="assets/libs/jquery/jquery.1.11.2.min.js"></script>
    <script src="assets/libs/jquery/jquery-ui.min.js"></script>
    <script src="js/bootstrap.js"></script>

    <script src="assets/libs/angular/1.3.12/angular.js"></script>
    <script src="assets/libs/angular/1.3.12/angular-route.js"></script>
    <script src="assets/libs/angular/1.3.12/angular-cookies.js"></script>
    <script src="assets/libs/angular/1.3.12/angular-sanitize.js"></script>

    <script src="app/sejour/prestation/prestation.js></script>

    <script src="app/sejour/fournisseur/fournisseur.js?v=1.0.4"></script>
    <script src="app/sejour/sejour/sejour.js?v=1.0.4"></script>
    <script src="app/sejour/sejour/sejour_edit.js?v=1.0.4"></script>
    <script src="app/services/fournisseur_service.js?v=1.0.4"></script>
    </head>

For the last 4 lines, i want to change "1.0.4" by a dynamic variable, I don't want to right it manually 对于最后4行,我想通过动态变量更改“ 1.0.4”,我不想手动对其进行纠正

If u can see, there are no controller added in this step, because it is the first step to load Angular and its features 如果您可以看到,则此步骤中未添加任何控制器,因为这是加载Angular及其功能的第一步

Thanks 谢谢

Try this: 尝试这个:

Make your script tags have no src and have the class dynScr , then put this in your head. 使您的脚本标签没有src并具有dynScr类,然后将其放在您的头上。

<script>
document.querySelectorAll(".dynScr")[0].src="app/sejour/fournisseur/fournisseur.js?v="+(new Date()).getTime();
document.querySelectorAll(".dynScr")[1].src="app/sejour/sejour/sejour.js?v="+(new Date()).getTime();
document.querySelectorAll(".dynScr")[2].src="app/sejour/sejour/sejour_edit.js?v="+(new Date()).getTime();
document.querySelectorAll(".dynScr")[3].src="app/services/fournisseur_service.js?v="+(new Date()).getTime();
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Angular SPA中将Controller添加到index.html - Add Controller to index.html in an Angular SPA 如何使用angularJS将脚本动态添加到index.html? - How to dynamically add the script to index.html using angularJS? 如何在index.html文件中为脚本导入src - How to import src for a script in index.html file 如何将src文件中的js文件导入index.html? - How to import js file from src file into index.html? 如何在索引中使用 *ngIf.html angular 8 - How to use *ngIf in index.html angular 8 带有AngularJS的Google标记管理器-如何从Angular组件访问Index.html头部分中声明的变量 - Google tag manager with AngularJS - how to access variables declared in the head section of Index.html from Angular component 如何以角度重新加载index.html头标记中存在的脚本? - How to reload the script present inside head tag of index.html in angular? 在运行时将脚本标记添加到index.html - Add script tag to index.html during runtime 如何在不触及index.html的情况下将外部javascript标记添加到Ember JS应用程序? - How can I add an external javascript tag to an Ember JS app without touching the index.html? 如何通过<a>HTML 中</a>的<a>标签</a>强制下载“index.html”文件 - How to force download of "index.html" file via an <a> tag in HTML
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM