Stop images from caching in Rails and browser? - ruby-on-rails

I have created a image crop facility that I can click on an image and crop it and it saves the new cropped image over the old one, then redirects back to the original page where the image was show.
But it still shows the old image even after a redirect and doesn't display the new one till I refresh the page.
I have tried just using an image tag and removing the asset timestamp after the image but it still displays the old image and I have also tried adding meta tags to stop browser caching but not working.
How can I solve this without having to do a refresh page?

It's probably not the best way, but I've solved this problem in the past by simply appending a timestamp to the image URL using JavaScript:
http://www.mysite.com/img/some_image.jpg?timestamp=12342312412
Next time it loads, the timestamp is set to the current time and the URL is different, so the browser does a GET for the image instead of using the cached version.

Are you using the rails image helper tag: image_tag in your views?
Rails automatically appends a timestamp based on the last modified date of the image file which is handy because it should change when you do your crop and write out the new image.
More information in the docs: http://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html

Related

How To Get External URL thumbnail iOS

i want to present a URL for example (http://edition.cnn.com/) with a thumbnail image from the site
do i need to Use Web View or try to extract images from the HTML, or there is a better solution ?
thanks.
It depends on what you want to see in the thumbnail image.
If you want to see a rendered preview of the site, then loading the page on a web view and taking a screen shot of that could be a way to go.
If you want to present an icon instead, you could load the source and scan it for a meta tag that contains the site's icon image. (such as og:image for example) and then download that.

How to restrict right click option on the image?

I m designing my portfolio in ruby on rails. In order to restrict the image from being copied, i wanted to disable the right click and other features of copying an image from the website. How to do it?
In most modern browsers you can disable the right-click menu for a particular image. To do so, you can use the event handler oncontextmenu="return false;" within the IMG tag that defines your image:
<IMG border=0 src="..." oncontextmenu="return false;">
For example, the context menu has been disabled for this image:
Note: In older browsers (e.g. Internet Explorer 4.x or earlier) this trick won't work. Also, the context menu will show up if the user has disabled JavaScript.
As all others already said: It's not possible in a reliable way. Only thing you can consider is to watermark your images.
You can disable the right click with javascript.
However, this is a pretty bad idea.
Since your images are sent to the browser of the visitor, they will be accessible, either by displaying the source or analyzing the HTTP requests, in the cache files, or simply screenshoting.
You should not break the user navigation by disabling the right click, your images will be copiable and there's nothing you can do about it. Deal with it.
Sadly its not possible to stop people from copying an image on your page.
Simply disabling right click would not be enough, anyone could just view the source to see the image url
http://www.hypergurl.com/norightclick.html
This guy has mentioned that we can add a transparent gif image to restrict the copy function but i am not getting how to do it. I m displaying my images inside carousel. And carousel gets very tricky sometimes. Also ive uploaded my images in cloudinary so if a person can get the URL of an image then he needs certain parameters to access it which only the owner has.

How to refresh p:graphicImage which gets image from servlet?

I have multiple <p:graphicImage>s which gets the image from a servlet by ID. I need to refresh the image when the user has removed or changed the image, so that it disappears or changes instead of showing the old one.
How can I achieve this? Could I use JavaScript or jQuery for this?

Changing an image doesn't work

I have downloaded a MVC project from an Open source and I am trying to make it my own.
I want to change images and add different things, new pages etc...
When I am changing an image in the content folder (for example the logo appearing at the top of the master page) it is always showing the old one.
If I change the name to logo1 for example I can see the new logo but as long as I am using logo the old logo is showing even if I changed the image.
Do you have an idea of what is going on!
Thanks
The browser is caching the image, clear the cache and you should see the new image.

Refresh browser?

I am working with images and changing their sizes dynamically from the input I get from the user.
when I change the size of the image first time it doesnot reflect the changes when I click the refresh the page using the browser button the change gets reflected and after that tere is no need to click the refresh button
Please tell how shall I do it so that there is no need to click the refresh button of the browser ,the changes but get reflected at one shot.
Thanks
Ritz
Your browser is cacheing the image. One easy way to get around this is to append something to the image URL such as "?v=101", "?v=102", etc. where the number is a version # you track on each image.
E.g.:
http://mysite.com/image.jpg?v=101
http://mysite.com/image.jpg?v=102
http://mysite.com/image.jpg?v=103
...
Or:
http://mysite.com/imagegen.php?name=foo&v=101
http://mysite.com/imagegen.php?name=foo&v=102
http://mysite.com/imagegen.php?name=foo&v=103
...
You don't have to look at the version number in your code, but its presence on the URL makes the browser think it's a different resource and therefore load it again without having to refresh.

Resources