相关疑难解决方法(0)

如何强制Web浏览器不缓存图像

背景

我正在为两个无偿网站编写和使用一个非常简单的基于CGI(Perl)的内容管理工具.它为网站管理员提供HTML表单,用于填写字段(日期,地点,标题,描述,链接等)的事件并保存.在该表单上,我允许管理员上传与事件相关的图像.在显示表单的HTML页面上,我还显示了上传图片的预览(HTML img标签).

问题

当管理员想要更改图片时,会发生此问题.他只需点击"浏览"按钮,选择一张新照片然后按确定即可.这很好用.

上传图像后,我的后端CGI处理上传并正确地重新加载表单.

问题是显示的图像没有刷新.即使数据库保存正确的图像,仍会显示旧图像.我已将其缩小到图像在Web浏览器中缓存的事实.如果管理员点击Firefox /资源管理器/ Safari中的RELOAD按钮,则所有内容都会刷新,并且只会显示新图像.

我的解决方案 - 不工作

我试图通过写一个过去很远的日期的HTTP Expires指令来控制缓存.

Expires: Mon, 15 Sep 2003 1:00:00 GMT
Run Code Online (Sandbox Code Playgroud)

请记住,我在管理方面,我并不关心页面是否需要更长时间才能加载,因为它们总是过期.

但是,这也不起作用.

笔记

上传图像时,其文件名不会保留在数据库中.它被重命名为Image.jpg(在使用时简单地说出来).使用新图像替换现有图像时,名称也不会更改.只是图像文件的内容发生了变化.

网络服务器由托管服务/ ISP提供.它使用Apache.

有没有办法强制Web浏览器不缓存此页面中的内容,甚至图像?

我正在使用数据库实际"保存文件名"的选项.这样,如果图像被更改,IMG标签的src也将改变.但是,这需要在整个站点进行大量更改,如果我有更好的解决方案,我宁愿不这样做.此外,如果上传的新图像具有相同的名称(例如图像有点照片并重新上传),这仍然无效.

html caching image image-caching browser-cache

115
推荐指数
8
解决办法
19万
查看次数

HTML5中的自闭标签(空元素)

8.1.2.1的第6步HTML5规范的开始标记表示void元素可能只有一个/字符.我认为这样做更容易将XHTML的网站迁移到HTML5.

什么是最佳做法?

例如,如果我正在制作一个HTML5(<!DOCTYPE html>)的网站,我该怎么办?

  1. 没有斜线

    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    
    Run Code Online (Sandbox Code Playgroud)
  2. 用斜线

    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    
    Run Code Online (Sandbox Code Playgroud)

如果两者都在所有浏览器上正确呈现,那么我假设(1)没有斜线是要走的路,因为它更像是HTML5.

tags html5 element

30
推荐指数
5
解决办法
1万
查看次数

是否可以使用扩展名file.php.jpg执行PHP?

站点合法文件image_upload.php用于上传文件89471928047.php.jpg这是将tmp文件复制到同一图像文件夹的简单文件上传表单.他们如何设法执行它并通过它上传其他文件.有人知道这有可能吗? PHP version was 5.1.6正好在一小时前更新,或者按照主机的时间表更新5.3.8......真是巧合?

php security

10
推荐指数
3
解决办法
2万
查看次数

如何使用JS触发GIF动画?

我有一个播放一次的动画GIF(不循环).我希望它在点击时动画.我试过这样的事情:

 $('#plus').click(function(){
    $('#plus').attr('src','');
    $('#plus').attr('src','img/plus.gif')
 });
Run Code Online (Sandbox Code Playgroud)

希望快速重置src会触发动画,但没有运气.谁知道会怎么做?

javascript jquery gif animated-gif

6
推荐指数
1
解决办法
8447
查看次数

在Flask中使用相同的文件名渲染动态更改的图像

我有一个烧瓶视图功能如下:

@app.route('/myfunc', methods = ['POST', 'GET'])
def myfunc():
    var = request.form["samplename"]
    selected_ecg=ecg.loc[ecg['Patient ID'].isin([var])]
    selected_ecg = selected_ecg.drop('Patient ID', 1)
    arr = np.array(selected_ecg)
    y = arr.T
    x=np.array(range(1,189))
    plot.plot(x,y)

    #Remove the old file
    os.remove("static\graph.png")
    #Now save the new image file
    plot.savefig("static\graph.png")

    return render_template("outputs.html")
Run Code Online (Sandbox Code Playgroud)

Outputs.html:

<html>
  <head>

  </head>
   <body>
     <h1>Output page</h1>

      <img src="static/graph.png" />

   </body>

</html>
Run Code Online (Sandbox Code Playgroud)

我使用flask视图功能通过outputs.html文件显示图像.这里的问题是,服务的静态图像文件每次都会根据用户输入而不断变化.换句话说,我会根据用户选择的输入覆盖图像文件.

但问题是没有提供更改的图像文件.用于第一次渲染的旧图像文件仅针对用户的每个新输入显示.

我已经提到了有关在烧瓶中提供动态内容的旧帖子.但它们都没有用.

html python flask

5
推荐指数
1
解决办法
711
查看次数

部署 Angular 8 应用程序后缓存破坏

我有一个 angular 8 应用程序,并且经常在部署后我收到最终用户的抱怨说他们无法看到新功能。我是否需要合并缓存破坏。经过一番谷歌搜索后,我看到了以下命令

ng build --output-hashing=all
Run Code Online (Sandbox Code Playgroud)

我的问题是使用 angular 8 cli 的 ng build --prod 是否考虑了缓存破坏,或者我是否需要在部署步骤中添加以下命令。我也想知道怎么测试

我的 angular.json

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "quickapp": {
      "projectType": "application",
      "schematics": {
        "@schematics/angular:component": {
          "style": "css"
        }
      },
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.app.json",
            "aot": false,
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.css",
              "src/app/assets/styles/components/buttons.css",
              "src/app/assets/styles/components/forms.css",
              "src/app/assets/styles/components/inputs.css",
              "./node_modules/bootstrap/dist/css/bootstrap.min.css",
              "./node_modules/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css"
            ],
            "scripts": …
Run Code Online (Sandbox Code Playgroud)

angular

5
推荐指数
1
解决办法
9703
查看次数

Javascript调整大图仅适用于F5之后

我使用这个javascript调整大小,最大为800px,页面上的大(5Mb)图像:

 <script type="text/javascript">
 $(document).ready(function () {
     $('.detailImg').each(function () {
         var maxWidth = 800; // Max width for the image
         var maxHeight = 800;    // Max height for the image
         var ratio = 0;  // Used for aspect ratio
         var width = $(this).width();    // Current image width
         var height = $(this).height();  // Current image height

         // Check if the current width is larger than the max
         if (width > maxWidth) {
             ratio = maxWidth / width;   // get ratio for scaling …
Run Code Online (Sandbox Code Playgroud)

javascript jquery

2
推荐指数
1
解决办法
1602
查看次数