I have a function which displays images from a binded uri (ie; www.website.com/picture1.jpg).
I have found and now understand that the phone caches the images that are downloaded. I read that its only for the life of the runng of the app, but even when I close the app and go back into it the same images from the cache come up.
Is there a way to stop this caching happening at all for this particular page?
EDIT: The images update regularly, but still have the same name, hence the need not to cache. Think security camera for example.
Many thanks.
There's no way around it unless you add a random query string to the image uri on each GET i.e.
var imageUrl = "www.website.com/picture1.jpg";
var imageUri = new Uri(String.Format("{0}?{1}", imageUrl, Guid.NewGuid()));
The caching is a little too aggressive - If doing a GET to the same Uri on any http request for the applications life cycle - Even if the content changes every time - The phone will cache it. It kept me puzzled for hours when I was trying to talk to a JSON-RPC web service...
Of course in general you will want images to be cached - But if you're sure the images you're after will be changing frequently then the above will work.
Add a unique querystring parameter to the URL. (eg, DateTime.Now)
There is CreateOptions property on BitmapImage (if you are loading in code) which lets you specify BitmapCreateOptions,one of which is IgnoreImageCache: Loads images without using an existing image cache. This option should only be selected when images in a cache need to be refreshed.
I've not tried it out, but it sounds like the kind of thing you are looking for ... if you do try it, I'd be interested in the result.
Depending on if you have control over the website and its content; shouldn't this be handled by setting the HTTP Response headers?
I would assume the platform respects the headers (unverified).
Otherwise the above posted random string trick will work.
Cache is a good thing , cause in your case, it can save the cost to download the image, if the image is not change, why you need to download it again?
if your image had been changed, and you want to enforce to download it again, you can generate a unique id at the url.
but think about it, why?
Related
I'm working with webbrowser tool trying to build my own browser.
Something that i'm having trouble doing is the history part.
When the document completes navigating , I search in my database if its URL doesn't exist then I add it to the history, else I just increase the "counter" of this page in the database.
The problem is that when I enter some pages each time it gives me different URL but it's the same page ! such as google.com , when I navigate to it it gives me in the first time (for example) : https://www.google.co.il/?gws_rd=cr&ei=eBP-UtPCOMi84ASukoCAAw
the second time I navigate :
https://www.google.co.il/?gws_rd=cr&ei=rhP-UpW6CYG54ATAqIHIDg
Is there a way to identify that both these URLs lead to the same page ??
I'm trying to do this because when I load the history to my application , many URLs are loaded that are leading to the same page.
Any help is appreciated , thanx in advance
You can use the Uri object and ask for the AbsolutePath property
I personally would expect my browser to have the history by URL and not by content (that's what you actually try to do as far as I understand). But if you want to avoid these multiple entries, you might calculate a hash code for each content received by that page and increase your counter.
The problem is that you cannot know what the server will do with that URL. It might be the same today and different tomorrow. I also wouldn't just go for the URL without the parameters because on other pages the parameter might make a really important difference.
Another note: In case you hash the content, you might want to exclude things like 404 pages (which can occur with different URLs and shouldn't be grouped under the same hash.)
Currently we have a page, where people can amend (crop, resize, etc..) images they have uploaded into the system. Everything works fine, but we have to improve the performance, especially the page load, so I'm looking for some advice.
The problem is that on our page, we have to display around 70-80 images. The source of all the images () are set to point to a Controller method, as we have some special rules in place to build up the full path of the images. (no DB calls are made there)
Obviously, this results in many calls to retrieve the images, which's ok up to a point, but after a while, it just becomes slower and slower.
So the questions is: What would be the best way to go about handling such a scenario?
Would it make any difference if instead of a Controller method we would use an HttpHandler to return the images?
Any input is greatly appreciated.
You can use images lazy loading plugin for jquery.
example: http://www.appelsiini.net/projects/lazyload
can you stitch the images together at the server, transmit them as a single ImageMap, then use CSS sprites (http://css-tricks.com/css-sprites/) on the page to display them?
This is a rather weird question, so please bear with me.
There's a SWF file on one page that, when you click on a 'Start' button loads some image. The URL to this image is passed as a SWFObject variable. I would like to change this image to one I have uploaded on my host.
I have tried setting a breakpoint on the line that pushes the image URL variable to the object and setting my URL, but the image wouldn't load because of cross-domain policy.
Now I am thinking of writing a simple c# proxy which will return my image instead of the real one when Flash requests it ...
Do you perhaps have any better ideas on how this could be done?
To sum it up, I want to replace an image that SWF loads from a constant URL to a custom image of mine. Decompiling is not an option.
EDIT: I figured out the image-not-loading problem, it was cached after all.
Too long for comments:
It's entirely possible that your SWF file has the image embedded in itself. However, you say a number of things that sound very conflicting to me.
First off, you mention putting a breakpoint on the line that "pushes the image URL variable to the object" What, exactly, does this? Is that the C# code?
You also state that it doesn't load due to cross-domain policy. Have you resolved that? Also, why do you think that's the problem?
Why did you try replacing the image with other tools? Are you trying to manually get around a cross-domain policy restriction?
Finally, you ask state that you "can't figure out why the image packets are not being received." Before we go that far, are they even being requested? You mention that wireshark doesn't even see the request going out..
I guess all of this boils down to:
1. Do you have control over where the SWF loads the image from?
2. If so, is that request being made? You should be able to see this from your server logs.
I am using an HttpHandler to modify some CSS (only simple colours) on the fly, based on a technique I read about on SO.
Everything works just fine expect on the page where I am giving the user the option to specify the colours they want. Ideally as soon as the user saves his new colours and the page refreshes I want the new colours to be displayed. However they only come through when I explicitly press the browser reload or F5 key.
I appreciate that something somewhere (IIS or the browser) is doing some helpful caching of my stylesheet which 999 times in 1000 is exactly what I want, however on this particular page event I want to be able to force a reload and cause the HttpHandler to fire.
Anyone understand how this works and what I can do?
Things I have tried:
Response.Clear();
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Expires = -1;
Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
Because I am also using ASP.NET themes adding a querystring the stylesheet link isn't really a simple option.
Thoughts anyone?
This can be solved with technique that I use on my sites to cause reloads of assets once they have changed, such as after a deploy.
Append ?value to the end of your CSS url, where value corresponds to the version, or some unique value the browser hasn't seen yet. In my case I use the file modification time, however in your case since the CSS is dynamic on almost every pageload, I suggest generating some unique value.
Since the URL is always different, the browser will always reload it and it will never get put into its cache.
Looking for information - I am creating a catolog website that includes a list of products. Each product has an image stored stored on the hard drive on the server. If the image does not exist, I want to show a default image. Whats the best way of doing this. I am using C# and considered checking on the server side if the image exists. But as some pages could have 50-60 images this would slow down the page. I use jquery on the client side. Any tips on this?
This is a great question, as the sitation arises in many circumstances. I see several options:
1) check for image availability during rendering of the catalog and use a link to the default image for items that do not have an image,
2) check for image availability in the image controller and return the default image when not available
3) put images inline in the document using data URLs
A major factor here is the possibility of caching.
Option (1) facilitates caching of the default image, but precludes caching of the catalog page. It is better if there are many items without an image, then such items will not even generate a hit to the server Furthermore, if there's a low chance that an image would appear for an item, you could cache the index too (for a reasonably short time).
Option (2) facilitates caching of the index page, but each image will have to send a request to the server. Again, you could use aggressive caching to avoid the same requests the second time the page is rendered.
Option (3) is best if your images are small and if the catalog page is relatively static. Be sure to use caching on the server side though while generating the page to reduce the load on the filesystem/database.
Sounds like this is a web application, so you should look into doing some caching. Even though image file lookups are expensive, once your page gets hit a few times the disk lookups will no longer be necessary.
Or you could store the information about whether a product image exists in your database. Then you prepopulate the database with the information and no disk checks are necessary.
Your best bet is to do this server-side as you suggest. You could do it client-side (attempt to load image, and load a default image if that fails), but this is not really what client-side scripting is designed for. You're making the user do extra HTTP requests, which is slower for the user.
An even better solution, as marcind suggests, is to pre-populate the database with default images. So in your CMS, when you create a new item, it assigns a default image URL to itself. You can then manually change it from there.
How does your jQuery code know the name of the image?
Seeing that your image files are physical files on the server and are accessible from a browser, I'd probably leave that part as is since that implies you don't have to serve the images yourself and IIS can handle that for you as a static file.
So your jQuery code obviously know the name of the image for each product. I assume this name is given to it by some server side process, so that process needs to give it either the name of the image for the product or the default image.
Some part of your code has to go through the process of figuring out if an image exists for the product and react accordingly. If you're using a database for your products that you could have a field in product table that indicates if the product has an image or not.