0

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 href="http://106.232.2.2:3000/assets/css/bootstrap-5c674533b683d85b12a4a4b13ee83e70.css" rel="stylesheet">
<link href="http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css" rel="stylesheet">
<link 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 href="$SERVER_HOST/assets/css/bootstrap-5c674533b683d85b12a4a4b13ee83e70.css" rel="stylesheet">
<link href="http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css" rel="stylesheet">
<link href="$SERVER_HOST/assets/css/mint-admin-78ba3e0ba257aa211af6ecf2ddf7f553.css" rel="stylesheet">
1
  • How about using DNS? Commented Dec 27, 2015 at 3:16

2 Answers 2

1

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);
Sign up to request clarification or add additional context in comments.

2 Comments

Hi, Does some js tool like require.js or webpack can do this ?
Those are for handling module dependencies. I'm pretty sure you can accomplish that with properly configuring require.js and requiring the appropriate modules, However you could use the above snippet. Lightweight and easy to understand.
1

Try something like this.

var baseUrl = 'http://106.232.2.2:3000';

var urlArray = ["/assets/jquery-9e7b5a8e0157d7776b987d8963c9c786.js?body=1",
                "/assets/jquery_ujs-38e73f935d8e2feac7f47b8c67317969.js?body=1"];
var s;

for(var i = 0 ; i < urlArray.length; i ++) {
    s = document.createElement('script');
    s.src = baseUrl + urlArray[i];
    document.getElementsByTagName('head')[0].appendChild(s);
}

Option 2 (HTML option)

<base href="http://106.232.2.2:3000/">
<script src="assets/jquery-9e7b5a8e0157d7776b987d8963c9c786.js?body=1" data-turbolinks-track="true"></script>
<script src="assets/jquery_ujs-38e73f935d8e2feac7f47b8c67317969.js?body=1" data-turbolinks-track="true"></script>
<script src="assets/comment-ce9e9195c9ca532a7968ea39a6e1f67f.js?body=1" data-turbolinks-track="true"></script>

3 Comments

i can understand this way, but it seems not so intuitive to do so. but still thx for your suggestion :)
@newBike Give a try with Option2
Hi, Does some js tool like require.js or webpack can do this ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.