开发者

Program to Change all images urls in the html response to be downloaded from two domains

I need some help in trying to figure out the java code to replace image URLs with two domains (mapping to the same site), to ensure that IE can download those files in parallel (achieve more than 2 files download trick for IE). My Basic Design is have a ResponseWrapper filter which has the handle on response data.

Now once I have the html string, I want to replace every img url with 2 domains alternatively

I have the html with me which contai开发者_JS百科ns the following patttern as an example

<... href="/img/abc/def.jpg/> <....src="/img/ghi/ijk.jpg/> <....src="/img/ghi/xyz.jpg/> <... href="/img/abc/lkm.jpg/>

I want to find this pattern and replace it with the following string

<... href="http://test1.com/img/abc/def.jpg/> <....src="http://test2.com/img/ghi/ijk.jpg/> <....src="http://test1.com/img/ghi/xyz.jpg/> <... href="http://test2.com/img/abc/lkm.jpg/> and so on.

Can somebody give me an idea of what should be the logic or algorithm to do this pattern replacement?


Rather than attempting to do this on the response text itself, you should create a method to generate URLs. This method would randomly pick a host from some configured list (there's no good reason to strictly alternate).


Here's what I do, and I would suggest you to do the same:

  • put your main domain with www
  • put your images domain #1 into im1
  • put your images domain #2 into im2

In your web pages, just put full links to images like:

  • http://im1.example.com/image1.jpg
  • http://im2.example.com/image2.jpg

But my first advice would be: read carefully all the recommandations from the YahooSlow plugin, which are the best ones about website optimization.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜