Answer the question
In order to leave comments, you need to log in
How to set index folder via .htaccess?
Hello. Here on Open Server there is a domains tab, where you can set an index folder, for example, the "public" folder.
Not all hostings have the ability to set an index folder :(, how can this be done using .htaccess?
How will this all affect performance?
Thanks in advance!
Answer the question
In order to leave comments, you need to log in
Here's how to send requests one by one using promises one by one
var promise = Promise.resolve();
var result = []
for(let i =0; i< 3;i++){
promise = promise.then(()=> $.ajax(
{
url: urlToCreated + '/' + id,
type: 'GET',
dataType: 'json',
data: {skip: skip, limit: 100000},
}
).promise().then(function (data) {
result.push(data)
}))
}
Here is a good es5 example, without Promise and async/await if that matters to you:
var result = {};
deferredParallel([1, 2, 3, 4, 5], function (id) {
return $.ajax({
url: urlToCreated + '/' + id,
method: 'GET',
dataType: 'json',
data: {
skip: skip,
limit: 100000
},
success: function (data) {
result[id] = data;
}
});
}).done(function () {
console.log(result);
});
function deferredParallel(items, callback) {
var deferreds = [];
for (var i = 0; i < items.length; i++) {
var deferred = callback(items[i], i, items);
if (typeof deferred === 'object' && deferred.done && deferred.fail) {
deferreds.push(deferred);
}
}
return $.when.apply(null, deferreds);
}
var result = [];
deferredParallel([1, 2, 3, 4, 5], function (item) {
return $.ajax({
url: 'https://jsonplaceholder.typicode.com/posts/' + item,
method: 'GET',
dataType: 'json',
success: function (data) {
result.push(data);
}
});
}).done(function () {
console.log(result);
});
function deferredParallel(items, callback) {
var deferreds = [];
for (var i = 0; i < items.length; i++) {
var deferred = callback(items[i], i, items);
if (typeof deferred === 'object' && deferred.done && deferred.fail) {
deferreds.push(deferred);
}
}
return $.when.apply(null, deferreds);
}
var result = [];
deferredQueue([1, 2, 3, 4, 5], function (item) {
return $.ajax({
url: 'https://jsonplaceholder.typicode.com/posts/' + item,
method: 'GET',
dataType: 'json',
success: function (data) {
result.push(data);
}
});
}).done(function () {
console.log(result);
});
function deferredQueue(items, callback) {
var ready = $.Deferred();
;(function fire (i) {
var deferred = callback(items[i], i, items);
if (typeof deferred === 'object' && deferred.done && deferred.fail) {
deferred.done(function () {
items[i + 1] ? fire(++i) : ready.resolve();
});
}
}(0));
return ready;
}
In your case, you need to use an async/await statement in a loop; So each next request will wait for the completion of the previous one.
.htaccess files can be scattered across any folder. They will work in the order in which they meet.
For example, when requesting example.com/shop/toys/cars
, Apache will check if there is .htaccess in the /shop folder, then if it is in /shop/toys and so on. Unless, of course, the first encountered htaccess does not interrupt this chain with some rule.
In this case, .htaccess files that are in some other folders will not be used. That is, if you have some /public/.htaccess but the request is not directed to the /public folder, it will not be used.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question