Giter Site home page Giter Site logo

Too many js files being cached about rack-cors HOT 10 CLOSED

cyu avatar cyu commented on July 23, 2024
Too many js files being cached

from rack-cors.

Comments (10)

cyu avatar cyu commented on July 23, 2024

This isn't coming from rack-cors. What version Rails are you using? What are you using to load the application js file?

from rack-cors.

cyu avatar cyu commented on July 23, 2024

Looks like you're using jQuery? See if passing cache: true to your ajax call does the trick:

http://api.jquery.com/jQuery.ajax/

from rack-cors.

amplicity avatar amplicity commented on July 23, 2024

rails -v: 3.2.12. I'm using asset pipeline. i've done

    rake assets:clean
    rake assets:precompile

code to query

       $.ajax({
      beforeSend: function (xhr) {
          xhr.setRequestHeader ('Authorization', api_key);
      },
      cache: false,
      dataType: 'html',
      type: 'GET',
      url: url+'/gwsearch/ajax_search?d1='+d1_val+'&d2='+d2_val,
      crossDomain: true,
      success:function(result){

        $("#display").html(result);
      },
      error: function(result) {
        $('#display').html('Unauthorized client.');
      }

rails responds with

respond_to do |format|

  format.html #responds with html
   if params[:callback]
   format.js { render :json => {:items_by_tag => @gw_search_results.to_json}, :callback =>    params[:callback] }
   else
    format.js
   end

  end

from rack-cors.

amplicity avatar amplicity commented on July 23, 2024

changed to cache: true, no go unfortunately @cyu

 $.ajax({
  beforeSend: function (xhr) {
      xhr.setRequestHeader ('Authorization', api_key);
  },
  cache: true,
  dataType: 'html',
  type: 'GET',
  url: url+'/gwsearch/ajax_search?d1='+d1_val+'&d2='+d2_val,
  crossDomain: true,
  success:function(result){

    $("#display").html(result);
  },
  error: function(result) {
    $('#display').html('Unauthorized client.');
  }

from rack-cors.

cyu avatar cyu commented on July 23, 2024

What's causing application.js to load though? Is it in the HTML returned by the ajax_search call?

from rack-cors.

cyu avatar cyu commented on July 23, 2024

Here's more info on the subject:

http://stackoverflow.com/questions/1537032/how-do-i-stop-jquery-appending-a-unique-id-to-scripts-called-via-ajax

I'm not sure if there is a suitable solution for this. Sounds like the best thing to do is to request those scripts outside HTML response.

from rack-cors.

amplicity avatar amplicity commented on July 23, 2024

Yes, it's through a script tag in the HTML response

<script src="http://localhost:3000/assets/application.js" type="text/javascript"></script>

I'm going to try the hack in the question you referenced and see if that works first, I'd rather not have to load the scripts outside the html response if I don't have to.

from rack-cors.

amplicity avatar amplicity commented on July 23, 2024

Using this worked:

$.ajaxPrefilter('script', function(options) {
options.cache = true;
});

Thanks for the help @cyu

from rack-cors.

amplicity avatar amplicity commented on July 23, 2024

@cyu Actually, I'm having the same original problem, which I thought had to do with multiple javascripts being delivered.

After my page is requested through ajax cross domain, it has input buttons on it. When I click one of them, it does this:

 <%= form_tag plans_collapse_plans_path, :method => 'post', :remote => true do %>
          <%= hidden_field_tag(:plangroup_id, plangroup.id) %>
          <%= image_submit_tag "collapse.png" %>
 <% end %>

The collapse_plans post will be sent however many times I made the initial ajax request. When I look at the request of the input button, it mentions something in the javascript about cors. Could this have anything to do with rack-cors? Something is being reinitialized or loaded everytime I send the initial ajax request for the page. Is it the input form in the html page or the jquery being reinitialized each time? Is there anything I can set in cors to possibly mitigate this?

from rack-cors.

cyu avatar cyu commented on July 23, 2024

I'm not exactly sure what the problem is, but I'm guessing that anything to mitigate this is really out of scope of this gem.

Closing this as this issue isn't caused by Rack::Cors.

from rack-cors.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.