2016-12-30 19 views
2

私は以下のように外部jsとcssのURLを持っています。これらのURLは、メインアプリケーションに関連していないapisです。私はバンドルを行うと、これらのURLのファイルにASP.NET MVCで外部のスクリプトとスタイルシートファイルを一括してバンドルする方法

Dim urls(5) as string 
urls(0)=http://localhost/media/10/custom.js 
urls(1)=http://localhost/media/11/custom1.js 
urls(2)=http://localhost/media/12/custom2.js 
urls(3)=http://localhost/media/10/custom3.js 
urls(4)=http://localhost/media/10/custom4.js 

BundleTable.Bundles.Add(New ScriptBundle("~/Content/js").Include(urls)) 
BundleTable.EnableOptimizaions=True 

を縮小化したい

http://localhost/media/10/custom.js, 
http://localhost/media/11/custom1.js, 
http://localhost/media/12/custom2.js, 
http://localhost/media/13/custom3.js, 
http://localhost/media/14/custom4.js 

私は以下のエラーを取得しています:

the URL '....' is not valid. Only application relativenURLs (~/url) are allowed.

はどうやって外部ファイルをバンドルすることができますか?

+2

**アプリケーションrelativenURLs(〜/ url)のみが許可されています** – Shyju

答えて

1

外部リソースをバンドルする方法はありません。あなたはbunlderは(それが要求を最小限に抑えるためのお手伝いをしません)それらをダウンロードし、リソースが更新されたかどうかを確認する必要がありbunlde外部リソースであれば、それは、MSDN Bundling and Minification

Bundling is a feature that makes it easy to combine or bundle multiple files into a single file. Because bundling combines multiple files into a single file, it reduces the number of requests to the server that is required to retrieve and display a web asset, such as a web page.

によると、全く意味がありません。

When the browser requests the script file it will be automatically served by the CDN "edge cache" server that is closest to the end-user. This means:

  1. The request will be processed much faster than if it had to hit your web-server (making the end-user's page load much faster)

  2. You don't have to pay for the bandwidth of this file – since the file comes from our server we pay the bandwidth cost (saving you money)

  3. The script can be easily cached across multiple web-sites – which means it might not even need to be downloaded if the user has already hit a web-site that requested the file (and as such has it already in the browser's cache).

サーバーにそれらをダウンロードするが、ちょうどそれらにリダイレクトされません。

はい、あなたがAnnouncing the Microsoft AJAX CDNに行けばあなたが見る、CDNのリソースをバンドルできます。それは違いを生みます。

さらに1つの利点がありますが、ブラウザには各ホスト名ごとに6つの同時接続の制限があります。 cdnを使用することで軽減できます。 cdnはホスティングサイトとは異なるホスト名を持つためです。

+0

cdn URLをバンドルできます。これらのURLはcdnのようなものなので、これらの外部js URLをバンドルすることができると思います。私が間違っている場合は私を修正してください。 –

+0

私はあなたのために答えを編集しました。 –

+0

jsファイルのこれらのURLは、私たちが生成しているものは、cdnsと似ていますか違うのですか?これらのファイルをバンドルすることは可能ですか?私は私のアプリケーションのためにこれらのバンドルを行う必要がありますので、私に解決策を提案してください。 –

関連する問題