Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't load static image,when i put the jsbundle and images in server #5142

Closed
huangqiaobo opened this issue Jan 6, 2016 · 8 comments
Closed
Assignees
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@huangqiaobo
Copy link

"react-native": "^0.17.0"

I run the commond:
react-native bundle
--entry-file index.ios.js
--platform ios
--dev false
--bundle-output ./main.jsbundle
--assets-dest ./ \

then I get
main.jsbundle and assets/
I found that all of my image is in assets folder.

Then I push the main.jsbundle and assets into service.

Then I use the url to load the bundle :
jsCodeLocation = [NSURL URLWithString:[NSString stringWithFormat:@"http://10.10.30.96/ota/main.jsbundle"];

then i find that ,I cant load the image.

what's the right way to load static images from server?

@facebook-github-bot
Copy link
Contributor

Hey huangqiaobo, thanks for reporting this issue!

React Native, as you've probably heard, is getting really popular and truth is we're getting a bit overwhelmed by the activity surrounding it. There are just too many issues for us to manage properly.

  • If you don't know how to do something or something is not working as you expect but not sure it's a bug, please ask on StackOverflow with the tag react-native or for more real time interactions, ask on Discord in the #react-native channel.
  • If this is a feature request or a bug that you would like to be fixed, please report it on Product Pains. It has a ranking feature that lets us focus on the most important issues the community is experiencing.
  • We welcome clear issues and PRs that are ready for in-depth discussion. Please provide screenshots where appropriate and always mention the version of React Native you're using. Thank you for your contributions!

@huangqiaobo
Copy link
Author

I find that the RCTImageLoader load image from 'http://10.10.30.96/assets/.../image.png'.
But my assets is in 'http://10.10.30.96/ota/assets/.../image.png'
The RCTImageLoader get a wrong url.
then I find the code in resolveAssetSource.js

var match = scriptURL && scriptURL.match(/^https?://.*?//);

when I change the code like this

var match = scriptURL && scriptURL.match(/^https?://.*//);

Then I can get true image URL.

It's a bug?

@huangqiaobo
Copy link
Author

The image source is not need server URL only.The pathname is also necessary

@huangqiaobo
Copy link
Author

@frantic

@frantic
Copy link
Contributor

frantic commented Jan 14, 2016

Hey @huangqiaobo, this behaviour is intentional. When you build an offline bundle with react-native bundle command it is supposed to be used only from somewhere on local disk, not network. If you point React Native to your server location it will think it's using development server and will load JS and images every single time. Additionally, it won't work if your user doesn't have internet connection.

The better way to do this is by packaging everything into an archive, downloading and unzipping it somewhere into ~/Documents folder and pointing React Native there. There is a bunch of community projects that offer this functionality as a service.

I'm closing this as not-an-issue, but feel free to comment if you have any questions.

P.S. I do agree that that regex looks strange. Feel free to send a PR

@frantic frantic closed this as completed Jan 14, 2016
@sdyxch
Copy link

sdyxch commented Jan 17, 2018

+1

@huangqiaobo
Copy link
Author

@sdyxch rn不推荐在release包里面直接用server的bundle,事实上如果你的项目有在build的时候运行RN的脚本的话,那么在release包里面,jsbundle和assets已经有一份在mainbundle里面,release包直接加载mainbundle里面的jsbundle就可以了。如果你想做热更新,可以把mainbundle里面的jsbundle和assets复制到你可以控制的目录下。

@sdyxch
Copy link

sdyxch commented Jan 17, 2018

@huangqiaobo
我是打算直接把bundle,发布到cdn。。

@facebook facebook locked as resolved and limited conversation to collaborators May 24, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

5 participants