Static JSON files over CDN via JSONP

前端 未结 2 813
感动是毒
感动是毒 2021-02-04 12:52

I have a large amount of static/rarely changing data in JSON format. To improve my ASP.NET MVC application performance, I would like to move them to a CDN (Amazon Cloud Front).

2条回答
  •  北荒
    北荒 (楼主)
    2021-02-04 13:56

    I just found out this is somehow possible. I solved it like so:

    $(document).ready(function(){
        $.getJSON("http://example.com/staticjsonfile.json",function(data){
        //callback function isn't here
        }
    });
    function JsonWrapping(data){
        //It's really here
        alert(data);
    }
    

    This is not ideal, as you loose binding with the event that fired the Ajax request. So some hacking is required. However, it kinda gets the job done. I'd be very open to a better solution.

提交回复
热议问题