Improved JS bundle loading performance
Summary: @public RCTJavaScriptLoader was using an NSURLSessionDataTask to load local bundle.js files. While this works, it was non-optimal from a performance point of view. Reviewed By: @tadeuzagallo Differential Revision: D2522598 fb-gh-sync-id: b32981b3be4c336512d1462d3f4943b5aad34ae0
This commit is contained in:
Родитель
91e6c98ecd
Коммит
7fe7a2a26b
|
@ -23,15 +23,26 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
|||
// Sanitize the script URL
|
||||
scriptURL = [RCTConvert NSURL:scriptURL.absoluteString];
|
||||
|
||||
if (!scriptURL ||
|
||||
(scriptURL.fileURL && ![[NSFileManager defaultManager] fileExistsAtPath:scriptURL.path])) {
|
||||
if (!scriptURL) {
|
||||
NSError *error = [NSError errorWithDomain:@"JavaScriptLoader" code:1 userInfo:@{
|
||||
NSLocalizedDescriptionKey: scriptURL ? [NSString stringWithFormat:@"Script at '%@' could not be found.", scriptURL] : @"No script URL provided"
|
||||
NSLocalizedDescriptionKey: @"No script URL provided."
|
||||
}];
|
||||
onComplete(error, nil);
|
||||
return;
|
||||
}
|
||||
|
||||
// Load local script file
|
||||
if (scriptURL.fileURL) {
|
||||
NSString *filePath = scriptURL.resourceSpecifier;
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
NSError *error = nil;
|
||||
NSString *rawText = [NSString stringWithContentsOfFile:filePath usedEncoding:NULL error:&error];
|
||||
onComplete(error, rawText);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Load remote script file
|
||||
NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithURL:scriptURL completionHandler:
|
||||
^(NSData *data, NSURLResponse *response, NSError *error) {
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче