I'm working on a Rails app that renders a JavaScript in the head
of application.html.erb
with the following:
<head>
...
<script><%= render 'certified_mail/mail_list_loader.js' %></script>
</head>
The JS partial rendered with the code above makes an AJAX call with parameters passed via instance variables from the controller:
# _mail_list_loader.js.erb
document.addEventListener("turbolinks:load", function() {
$.ajax({
url: '/certified_mail/mail_list',
type: 'get',
data: {
page: <%= @page %>,
rut: <%= @rut || 'null' %>,
from: <%= @from || 'null' %>,
to: <%= @to || 'null' %>,
ids: <%= @outdated_message_ids.to_json.html_safe %>
}
});
});
Since Turbolinks merges the head
content from subsequent requests, every time the parameters for the AJAX calls change I have an extra script
being loaded in the head
, which results in unwanted extra requests, as shown in the image below:
How can I tell Turbolinks to not consider that specific script in the merging process so I can avoid having those extra calls?