I want to know how the web page loading progress bar works in FF when there is no content-length present in the http headers. I checked with google.com, it does not send content-length header but the progress bar works correctly. Is it a real progress bar or a fake one? If this is a fake one then how I can build a similar one.
I am building a iPhone app where I need to build a similar loading progress bar.
Update 1
@Robot Woods - I just searched "hello" on the google and I do see the progress bar at the bottom .. right now I am on Windows 7 and FF 3.6.13
Here is the response headers I am getting -
And I don't see any content lengt开发者_StackOverflow社区h header...
How FF can generate a progress bar if the content length is not present.. ??
I don't know what Firefox does, but if it were me, I'd look at the following:
The initial page usually loads pretty quickly. Start parsing it while it's still coming in and start grabbing the other resources (css, js, images, etc) the page calls for.
Use the progress bar to depict how long the supporting files are going to take, and estimate the page based on a pessimistic average of other files of that type that you've downloaded before.
What a lot of programs do with their progress bar when that have no information is provide a progress bar that slows down as it gets close to the end. It never quite reaches the end, but it continues to move as long as data continues to come in.
But what do you want to load? Is FF just an example of progress bar here?
If you want to connect to a network with NSURLConnection and show it's download progress, you can simply do it with UIProgressView object. Mind that I've skipped your data handling and just wrote the progress event.
//NSURLConnection Delegate Methods - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{ //length is a long long declared outside length = [response expectedContentLength]; } - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { NSNumber * recieved = [NSNumber numberWithUnsignedInteger:[data length]]; NSNumber * total = [NSNumber numberWithLongLong:length]; float ratio = [recieved floatValue] / [toplam floatValue]; [[YourUIProgressView progressBar] setProgress:ratio]; }
Good luck.
精彩评论