简体   繁体   English

添加了Bigcommerce Stencil JS程序包加载较晚

[英]Added Bigcommerce Stencil JS Packages Loading Late

Developing a custom Stencil theme for an upcoming Bigcommerce store and am running into a few issues. 为即将到来的Bigcommerce商店开发自定义Stencil主题,并且遇到了一些问题。 I'm relatively new to the JS module-loading/ES6 concepts but have added a few additional JS packages via jspm (as included in Stencil). 我对JS模块加载/ ES6概念还比较陌生,但是通过jspm(包含在Stencil中)添加了一些其他JS软件包。 The problem I am running in to is that these new packages don't work their magic until the page is fully rendered. 我遇到的问题是,这些新软件包在页面完全呈现之前无法发挥作用。 So, for instance, I am using a modal pop-up package, animatedModal.js, which is a jQuery package. 因此,例如,我使用的是模式弹出框,animationModal.js,它是一个jQuery包。 It's installed, it's working, but no matter where I instantiate the package in the module loader, the modal content shows on the page for about 2s before being hidden and working as it should. 它已安装,正在运行,但是无论我在模块加载程序中的哪个位置实例化软件包,模态内容在隐藏并按预期方式工作之前都会在页面上显示约2秒钟。 Same goes for anothe jQuery package, mmenu, I am using for navigation. jQuery包mmenu也是如此,我正在使用它进行导航。

This isn't even a FOUC, as it seems that these plugins aren't even being run, as I said, until the page is fully rendered. 这甚至不是FOUC,因为正如我所说,这些插件甚至在页面完全呈现之前都没有运行。 I would expect to never see the modal that animatedModal.js is working on or to see the navigation rendered before being hidden by mmenu. 我希望在mmenu隐藏之前,永远不会看到animationModal.js正在处理的模式,也不会看到呈现的导航。 Do I need to instantiate the packages differently since we are using System.js/Babel/es6-module-loader/etc.? 由于我们使用的是System.js / Babel / es6-module-loader / etc,我是否需要以不同的方式实例化软件包?

Currently, once the package is installed, I create a js file in /js/theme/global for the particular package, for instance, to use animatedModal.js I created /js/theme/global/animated-modal.js: 当前,一旦安装了软件包,我就在/ js / theme / global中为特定的软件包创建一个js文件,例如,使用我创建的/js/theme/global/animated-modal.js的animationModal.js:

import $ from 'jquery';
import 'joaopereirawd/animatedModal.js';

export default function() {
    $("#loginLink").animatedModal();
}

Then, in /js/theme/global.js I call this function/module: 然后,在/js/theme/global.js中,我将此函数/模块称为:

import initializeModals from './global/animated-modal';

export default class Global extends PageManager {
    // ...
    loaded(next) {
        initializeModals();
        // ...
    }
}

Again, this all works as it should, but the time it takes to load a page is quite long, and all these elements show on the page for about 2s before being hidden and "working," such as the modal being hidden and clickable or the navigation showing on-page before being hidden and usable. 同样,这一切都可以正常进行,但是加载页面所花费的时间很长,所有这些元素在被隐藏和“工作”之前在页面上显示大约2秒钟,例如被隐藏和单击的模式或在隐藏和可用之前在页面上显示的导航。

Any community thoughts out there? 有任何社区想法吗?

Why do you say this is not FOUC? 你为什么说这不是FOUC? The javascript it being initialized at the bottom of the HTML template, so of course the modules/functions don't run until the page has rendered to that point. javascript会在HTML模板的底部进行初始化,因此,在页面呈现到该点之前,模块/函数当然不会运行。 This means your HTML will display as it would before the javascript kicks in and hides it. 这意味着您的HTML会像显示javascript之前一样显示和隐藏。 You need to hide the content yourself with CSS. 您需要使用CSS自己隐藏内容。 Then the js will take over once it's loaded. 然后,js将在加载后接管。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM