If it's just object data in the mainSliderData.js file, you could perhaps use a json file instead containing your object data.
Create a file called mainSliderData.json with your object data...
{
"mainSliderData": {
"img1": "../vendors/img/slide1/slider.gif",
"img2": "../vendors/img/slide1/slider.gif",
"img3": "../vendors/img/slide1/slider.gif",
"img4": "../vendors/img/slide1/slider.gif",
"img5": "../vendors/img/slide1/slider.gif",
"img6": "../vendors/img/slide1/slider.gif",
"img7": "../vendors/img/slide1/slider.gif"
}
}
And then get the file using jQuery.getJSON()...
$.getJSON("../../data/mainSliderData.json", function(json) {
console.log("success");
console.log(json);
})
.done(function() {
console.log("done");
})
.fail(function() {
console.log("error");
});
Here is demo loading the above json from a remote json file at https://jsonbin.io/
$.getJSON and $.getScript are both shorthand functions of $.ajax, and because our remote jsonbin demo file is protected via a secret key, I am having to use $.ajax so I can setRequestHeader to authenticate json file access. But the results should be the same if you were using $.getJSON method on your json file url (which should not need send headers).
// headers function for demo only
var headers = function(xhr) {
xhr.setRequestHeader('secret-key', '$2b$10$yK4/uNbaGMm.XC8FPGB/UOSINcEoT38KOduwKAgKY8EQrt2owmN/G');
}
// jquery ajax call
$.ajax({
// essentially $.getJSON long hand
url: 'https://api.jsonbin.io/b/5f9a0539f0402361dcee11e6/2',
type: 'GET',
dataType: 'json',
// on success
success: function(json) {
console.log("success");
console.log(json.mainSliderData);
// example each function to handle json mainSliderData data
$.each(json.mainSliderData, function(id, path) {
// append slide image to body
$('BODY').append('<img src="' + path + '" alt="' + id + '" />');
});
},
// on fail
error: function() {
console.log("error");
},
// send headers for demo as remote json demo file is protected with secret key at https://jsonbin.io
beforeSend: headers
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
UPDATE
I just discovered on https://jsonbin.io/ I can create public json files...
Your mainSliderData json... https://api.jsonbin.io/b/5f9a12cf9291173cbca51786
So here is live demo using $.getJSON method...
// json file url
let json_file_url = "https://api.jsonbin.io/b/5f9a12cf9291173cbca51786";
// jquery get json call
$.getJSON(json_file_url, function(json) {
console.log("success");
console.log(json);
// example each function to handle json mainSliderData data
$.each(json.mainSliderData, function(id, path) {
// append slide image to body
$('BODY').append('<img src="' + path + '" alt="' + id + '" />');
});
})
.done(function() {
console.log("done");
})
.fail(function() {
console.log("error");
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
console.log(mainSliderData)?mainSliderData is not defined.