Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post May 03, 2012 11:16 AM by friendster
Member
57 Points
99 Posts
May 03, 2012 01:37 AM|LINK
Hi,
In my application, i hosted all my js file into google.
However, i would like to check the existence of the js file, if the js that located in google doesn't exist, then i will use the local js file.
How to write a function to check above condition?
Google js file
<script type="text/javascript" src="http://wormsearch.googlecode.com/files/ws-master-v1.min.js"></script>
Local js file
<script type="text/javascript" src="~/js/min/ws-master-v1.min.js"></script>
Star
8079 Points
1491 Posts
May 03, 2012 03:27 AM|LINK
<script src="http://wormsearch.googlecode.com/files/ws-master-v1.min.js"></script> <script>!window.jQuery && document.write('<script src="js/min/ws-master-v1.min.js"><\/script>')</script>
also you cannot use "~" - this is a server feature. please review ResolveURL
<script src="<%= ResolveUrl("~/js/min/ws-master-v1.min.js") %>" type="text/javascript" ></script>
9204 Points
1570 Posts
May 03, 2012 10:49 AM|LINK
For what it's worth I don't think this is a very good idea as it isn't efficient. You also might not need the "resolveurl" bit, just use "/js/...". But anyway.
ASPX
<script type="text/javascript" src="<%=Url %>"></script>
Code
public string Url { get; private set; } protected void Page_Load(object sender, EventArgs e) { Url = "http://wormsearch.googlecode.com/files/ws-master-v1.min.js"; WebRequest req = WebRequest.Create(Url); try { HttpWebResponse resp = (HttpWebResponse) req.GetResponse(); if (resp.StatusCode != HttpStatusCode.OK) { Url = ResolveUrl("~/js/min/ws-master-v1.min.js"); } resp.Close(); } catch { Url = ResolveUrl("~/js/min/ws-master-v1.min.js"); } }
749 Points
189 Posts
May 03, 2012 11:16 AM|LINK
You can check with the Web http respose by reading the file. if the status is not "OK" . you can apply the next thing,
My2ndLovE
Member
57 Points
99 Posts
Check existence of .js file
May 03, 2012 01:37 AM|LINK
Hi,
In my application, i hosted all my js file into google.
However, i would like to check the existence of the js file, if the js that located in google doesn't exist, then i will use the local js file.
How to write a function to check above condition?
Google js file
Local js file
robwscott
Star
8079 Points
1491 Posts
Re: Check existence of .js file
May 03, 2012 03:27 AM|LINK
<script src="http://wormsearch.googlecode.com/files/ws-master-v1.min.js"></script> <script>!window.jQuery && document.write('<script src="js/min/ws-master-v1.min.js"><\/script>')</script>also you cannot use "~" - this is a server feature. please review ResolveURL
<script src="<%= ResolveUrl("~/js/min/ws-master-v1.min.js") %>" type="text/javascript" ></script>Mark Answered if it helps - Good luck!
Cheers!
Design And Align
- Rob
AidyF
Star
9204 Points
1570 Posts
Re: Check existence of .js file
May 03, 2012 10:49 AM|LINK
For what it's worth I don't think this is a very good idea as it isn't efficient. You also might not need the "resolveurl" bit, just use "/js/...". But anyway.
ASPX
Code
public string Url { get; private set; } protected void Page_Load(object sender, EventArgs e) { Url = "http://wormsearch.googlecode.com/files/ws-master-v1.min.js"; WebRequest req = WebRequest.Create(Url); try { HttpWebResponse resp = (HttpWebResponse) req.GetResponse(); if (resp.StatusCode != HttpStatusCode.OK) { Url = ResolveUrl("~/js/min/ws-master-v1.min.js"); } resp.Close(); } catch { Url = ResolveUrl("~/js/min/ws-master-v1.min.js"); } }friendster
Member
749 Points
189 Posts
Re: Check existence of .js file
May 03, 2012 11:16 AM|LINK
You can check with the Web http respose by reading the file. if the status is not "OK" . you can apply the next thing,