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

The /^<!--/ regExp causes bug when injecting js to html #7298

Closed
mengjian-github opened this issue Dec 21, 2017 · 8 comments · Fixed by #7314
Closed

The /^<!--/ regExp causes bug when injecting js to html #7298

mengjian-github opened this issue Dec 21, 2017 · 8 comments · Fixed by #7314

Comments

@mengjian-github
Copy link
Contributor

mengjian-github commented Dec 21, 2017

Version

undefined

Reproduction link

https://jsfiddle.net/xjtumj/u04ornp4/

Steps to reproduce

when injecting vue to html, there is nothing to show in android webview.

try to replace /^<!--/ with /^<!\--/, the showing turns to be right.

suggest to escape the expression.

What is expected?

render correctly

What is actually happening?

not render correctly

@posva
Copy link
Member

posva commented Dec 21, 2017

try to replace /^<!--/ with /^<!--/,

What's the difference?
Please provide a valid repro when reporting a bug

@mengjian-github
Copy link
Contributor Author

@posva sorry for ignoring github editor's self encoding, I updated my written with '\' instead of ''

@posva
Copy link
Member

posva commented Dec 21, 2017

Why would - need to be escaped out of []. Could you provide the repro, please?

@mengjian-github
Copy link
Contributor Author

@posva because <!-- will be parsed to a comment tag in html files. When injecting code into a <script> tag, we would found nothing to be rendered in Android Webview.
I'm sorry that I couldn't provide a real repro because it's a private project. I have not found a simple way to reproduce yet. But it is really useful to replace <!-- with <!\--, it will not be treated as a comment tag that prevent the code execution after.

@posva
Copy link
Member

posva commented Dec 21, 2017

ah, I see, so it's a repro after all. What version and what browser are failing? The change is minimal but I want to make sure there's actually a problem

@mengjian-github
Copy link
Contributor Author

vue version: 2.5.2
android system version: 4.4.2

@yyx990803
Copy link
Member

This is weird, as it should not happen unless you are inlining the entire Vue codebase inside HTML. Why would you do that?

@mengjian-github
Copy link
Contributor Author

This is an optimization strategy for hybrid web page. There are a wide range of Android device used by our users, and most of them are lower-end, which means very low performance and network speed. For those who use these devices, the WebView native cache is not reliable, most of the time would be wasted on network requests. We found that injecting js/css files into html can effectively improve the speed when open pages, as it really reduce the RTT(Round-Trip Time) in weak-network environment. Also, we have offline packages which are supported by native app, this would be really fast that native app could prefetch html and cache them. In most circumstances, the page is loaded locally.

Without the SSR(need more machine and labor costs), it would be a good practice to inject js and css files into html, to get the significant performance optimization for most users who use the lower-end phone with weak-network environment.

yyx990803 pushed a commit that referenced this issue Dec 25, 2017
escape - to avoid regex being parsed as HTML comment when entire codebase is inlined.
fix #7298
lovelope pushed a commit to lovelope/vue that referenced this issue Feb 1, 2018
escape - to avoid regex being parsed as HTML comment when entire codebase is inlined.
fix vuejs#7298
f2009 pushed a commit to f2009/vue that referenced this issue Jan 25, 2019
escape - to avoid regex being parsed as HTML comment when entire codebase is inlined.
fix vuejs#7298
aJean pushed a commit to aJean/vue that referenced this issue Aug 19, 2020
escape - to avoid regex being parsed as HTML comment when entire codebase is inlined.
fix vuejs#7298
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants