How to replace script content without manually modification

- 1 answer

Ad

The following snippet seems need to repetitively type the same server host "http://106.232.2.2:3000/"

I wonder if there is any js toolchain can let me maintain this in more effective way like the example with my expectation. It should be run in pruly js without any backend techniques.

current version

<script src="http://106.232.2.2:3000/assets/jquery-9e7b5a8e0157d7776b987d8963c9c786.js?body=1" data-turbolinks-track="true"></script>
<script src="http://106.232.2.2:3000/assets/jquery_ujs-38e73f935d8e2feac7f47b8c67317969.js?body=1" data-turbolinks-track="true"></script>
<script src="http://106.232.2.2:3000/assets/comment-ce9e9195c9ca532a7968ea39a6e1f67f.js?body=1" data-turbolinks-track="true"></script>
<script src="http://106.232.2.2:3000/assets/application-52b017a9dbb00790db4e22316964e7d9.js?body=1" data-turbolinks-track="true"></script>
<link target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" href="http://106.232.2.2:3000/assets/css/bootstrap-5c674533b683d85b12a4a4b13ee83e70.css" rel="stylesheet">
<link target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" href="http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css" rel="stylesheet">
<link target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" href="http://106.232.2.2:3000/assets/css/mint-admin-78ba3e0ba257aa211af6ecf2ddf7f553.css" rel="stylesheet">

expected version

define SERVER_HOST =  http://106.232.2.2:3000
<script src="$SERVER_HOST/assets/jquery-9e7b5a8e0157d7776b987d8963c9c786.js?body=1" data-turbolinks-track="true"></script>
<script src="$SERVER_HOST/assets/jquery_ujs-38e73f935d8e2feac7f47b8c67317969.js?body=1" data-turbolinks-track="true"></script>
<script src="$SERVER_HOST/assets/comment-ce9e9195c9ca532a7968ea39a6e1f67f.js?body=1" data-turbolinks-track="true"></script>
<script src="$SERVER_HOST/assets/application-52b017a9dbb00790db4e22316964e7d9.js?body=1" data-turbolinks-track="true"></script>
<link target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" href="$SERVER_HOST/assets/css/bootstrap-5c674533b683d85b12a4a4b13ee83e70.css" rel="stylesheet">
<link target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" href="http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css" rel="stylesheet">
<link target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" href="$SERVER_HOST/assets/css/mint-admin-78ba3e0ba257aa211af6ecf2ddf7f553.css" rel="stylesheet">
Ad

Answer

Ad

I feel a bit of a contradiction there:

I wonder if there is any js toolchain ...

It should be run in pruly js without any backend techniques.

Anyway, you can insert those script andlink tags dynamically:

var SERVER_HOST = 'http://106.232.2.2:3000';
var scriptTag = document.createElement('script');
scriptTag.setAttribute('src', SERVER_HOST + '/assets/jquery-9e7b5a8e0157d7776b987d8963c9c786.js?body=1');
scriptTag.setAttribute('data-turbolinks-track', 'true');
document.head.appendChild(scriptTag);
Ad
source: stackoverflow.com
Ad