强制浏览器忽略缓存

编程入门 行业动态 更新时间:2024-10-24 04:48:03
本文介绍了强制浏览器忽略缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的代码裁剪了一张照片。裁剪的照片会不断更换,但浏览器只会加载第一个裁剪。我在网上搜索过,但没有任何效果。我已经在php中添加了随机字符串 - new.jpg?time = t - 但这可以防止裁剪的图像被保存。我已经包含了

My code crops a photo. The cropped photo is constantly replaced but the browser only ever loads the first crop. I have scoured the web but nothing has worked. I have added random strings to the php - new.jpg?time=t - but this prevents the cropped image from saving. I have included

<head> <meta charset="utf-8"> <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" /> <meta http-equiv="Pragma" content="no-cache" /> <meta http-equiv="Expires" content="-1" /> </head>

但浏览器仍然从缓存中加载。 HTML JavaScript和PHP如下。还有其他任何建议吗?

but the browser still loads from the cache. The HTML JavaScript and PHP follow. Any other suggestions?

<html> <head> <title>Image Crop</title> <style> body{ margin: 0; padding: 0; } #container{ width: 300px; } #box{ position: absolute; top: 0px; left: 0px; width: 100px; height: 100px; background: white; border: 2px solid blue; opacity: 0.5; } #crop_button{ background: #333; color: #fff; padding: 5px; border: 0px; margin: 5px; } #output{ position: absolute; top: 0px; left: 300px; } </style> </head> <body> <div id="container"> <img src="resized_IMG0934.jpg"/> <div id="box"></div> </div> <div id="output"><image /> </div> <button id="crop_button">Crop</button> <link rel="stylesheet" href="//code.jquery/ui/1.10.4/themes/smoothness/jquery-ui.css"> <script src="//code.jquery/jquery-1.10.2.js"></script> <script src="//code.jquery/ui/1.10.4/jquery-ui.js"></script> <script src="index.js"></script> </body> </html> $(function() { $('#box').draggable({containment: '#container'}); $('#box').resizable({containment: '#container'}); $('#crop_button').click(function(){ var top = $('#box').position().top; var left = $('#box').position().left; var width = $('#box').width(); var height = $('#box').height(); $.post('crop.php', {top:top, left:left, width:width, height:height}, function(){ $('#output').html('<img src="new.jpg"/>'); }); }); }); <?php $dst_x = 0; $dst_y = 0; $src_x = $_POST['left']; //crop Start x $src_y = $_POST['top']; //crop Start y $dst_w = $_POST['width']; //Thumb width $dst_h = $_POST['height']; //Thumb height $src_w = $_POST['width']; //$src_w + $dst_w $src_h = $_POST['height']; //$src_h + $dst_h $dst_image = imagecreatetruecolor($dst_w,$dst_h); $src_image = imagecreatefromjpeg("resized_IMG0934.jpg"); imagecopyresampled($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h); imagejpeg($dst_image, "new.jpg");

推荐答案

您有以下选择: - 添加以下元标记,这将强制不兑现

You have the following choices: - add the following meta tag, this will force not to cash

<meta http-equiv="pragma" content="no-cache" /> which you have already as I see

  • 此外,如果要加载新版本的css文件,请执行以下操作:
  • < link rel =stylesheettype =text / css href =mystyle.css?version = {NewVersionOnRequierd}>

    < link rel="stylesheet" type="text/css" href="mystyle.css?version={NewVersionOnRequierd}">

    • 图片相同
    • < img src="picture.jpg?123" alt="">

更多推荐

强制浏览器忽略缓存

本文发布于:2023-10-31 19:06:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1547001.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:缓存   浏览器

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!