最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Chrome VM files duplicate javascript - Stack Overflow

programmeradmin2浏览0评论

I have a problem developing a website. I am using chrome to debug javascript functions. On one of my pages I see the following:

You can see that my own javascript file gets executed, search.js. There is a duplicate of this file, called VM1769. This file also executes the same code, so a search request is sent twice.

I searched around, and saw someone solve this problem by disabling cache (while DevTools is open), but this did not work for me. I tried another version of Chrome, the problem is still here.

Does anyone have a solution?

I have a problem developing a website. I am using chrome to debug javascript functions. On one of my pages I see the following:

You can see that my own javascript file gets executed, search.js. There is a duplicate of this file, called VM1769. This file also executes the same code, so a search request is sent twice.

I searched around, and saw someone solve this problem by disabling cache (while DevTools is open), but this did not work for me. I tried another version of Chrome, the problem is still here.

Does anyone have a solution?

Share Improve this question edited Jun 11, 2015 at 12:41 Seki 11.5k7 gold badges48 silver badges72 bronze badges asked Mar 14, 2014 at 11:05 InigoInigo 3513 silver badges13 bronze badges 2
  • 1 This article seems to give more info: stackoverflow./questions/17367560/… – Sanford Staab Commented Dec 2, 2016 at 14:08
  • 1 Hey were you able to solve the issue? – Vedant Shah Commented Apr 30, 2022 at 2:25
Add a ment  | 

4 Answers 4

Reset to default 7

I got the same issue and found out that i really included the same JavaScript-File twice. So its not logical for me that Chrome shows the second execution as a VM-Script but it ended to do that when i deleted the duplicate include.

I had the same problem. In the template on my server I put my script tag inside of the main content container.

{% block content %}
    {% block js %}
        <script src='path/toJSFile.js'></script>
    {% endblock %}
{% endblock %}

Which means that after rendering my script was not at the bottom of the <body> tag but inside of div.container and for some reason after rendering I had two duplicated scripts instead of one. One in a div.container another at the bottom of the <body> tag. Second one was inserted automatically for some reason.

So after I moved script outside of the div.content container my script started behave as I expect. No duplicates, no double fetch requests.

{% block content %}
    ...
{% endblock %}

{% block js %}
    <script src='path/toJSFile.js'></script>
{% endblock %}

Though my answer represents a snippet from a django template this approach should work in other cases as well. My suggestion is: you definitely want to place your script in a proper place (head or body) not inside of any divs.

Hi I was getting this also and this was causing to have two duplicated chooses in my autoplete text input. What I did was just to create a global flag to know whether the script file was already executed or not. I know this is not the solution but I just wanted to share this here since blocking the execution of the VM file has fixed my problem but I need to know yet how definitely to resolve this.

I was experiencing this issue.

For me it was caused by webpack injecting a second instance of my javascript files for debugging.

Removing the last line (mode: "development") eradicated the duplicate script.

const webpack = require('webpack');

module.exports = {
    entry: {
        a: [./scripts/xxx.ts"],
        b: ["./scripts/yyy.ts"],
        c: ["././scripts/zzz.ts"]
    },
    output: {
        // runtime asset location
        path: __dirname + "/dist/js/bundles",
        filename: '[name].js',
        library: "$",
        libraryTarget: "umd"
    },
    plugins: [
        new webpack.CleanPlugin(),
    ],
    module: {
        rules: [
            { test: /\.ts$/, use: 'ts-loader', exclude: /node_modules/ },
        ],
    },
    resolve: {
        extensions: ['.ts'],
    },
    mode: "development"
};
发布评论

评论列表(0)

  1. 暂无评论