Server side: ASP.NET MVC 3 on Windows 2008 servers using IIS 7.5 Map services Operational layers (dynamic and feature layers) are on our ArcGIS Servers Basemap is the World Street Map layer from ArcGIS Online.
We have built some map applications to be consumed in pages built by other development teams. When our map applications load the first time for a user (or after clearing the browser cache), one or more layers fails to load.
Our in-house map services depend on database connections that are severed by the firewall when they are maintained for too long. We have timed jobs to reset those map services, but when they're cut off it can take a couple of minutes for them to be available to users. That's not the issue I'm talking about here.
The classes we added were modified from code found here at http://forums.esri.com/Thread.asp?c=158&f=2396&t=291261, but the other developers want the map to load first time, every time. I've been assuming this is a network issue - the code doesn't change, the map services don't change and the browser doesn't change - the only thing is a new call. Also, we changed to local installs of the JSAPI because we routinely get Dojo errors from the Esri CDN version not being found. Still, we need to get around this one.
A programmer on one of the other teams suggested the resources are not loading fast enough. Since the onLoad event is the only point I know of to determine when the API has loaded the layer, I've been checking it in debug. I even increased the number of retries and the timeout period. I found that if the layer didn't load the first time, it never will. But when I refresh the page, it loads the layers from the cache and it works. I clear the cache again, retry and it fails, then refresh and it works.
Has anyone else had a problem like this with their layers not loading?
The only response I got was to ask for code to reproduce the problem. Since the code is the same as any code to load a FeatureLayer, the code won't make a difference. I'm pretty sure it's our environment, over which I have no control, so it's unlikely to be reproducible. I was looking more for some advice on how to get around the policies of a network and security setup that is unfriendly to map services and applications.
I didn't actually resolve the cause. Our application just runs through the list of layers to load and tries creating each one in turn. After all have been created, if any haven't loaded, we just go through it again up to five times. If any don't load then, we alert the user to refresh the page.
It looks like you might be experiencing the "Sleepy services" issue, and it has nothing to do with JSAPI if you are using ArcGIS Server 9.3.x or 10.0.
This is more of a IIS behavior where default setting of an Application Pool on IIS is to recycle after 20 min of applications running under that pool being idle. Then when a user calls the services for a first time, it takes some time for the services to "wake up". And sometimes it requires a page refresh or a few for the services to load.
You can try to fix this by setting the Idle Time-out for the application pool to a higher number than 20 min (if there are times when the applications are not used for 4 hours for example, you can set the timeout to 240+ minutes). Also look at any other application pool recycling settings that might be causing the pool to shut down.
To make sure you modify the appropriate application pool, find out under what application pool are the ArcGIS\rest and ArcGIS\services applications running.
Please, consult your IIS administrator before you make the changes, as there are situations when they are not applicable (see articles above and search on your own more).