Giter Site home page Giter Site logo

wp-partytown's Introduction

WP Partytown

This plugin is a POC for ticket #176 in WordPress/performance repo.

Goals

  1. Allow plugin developers to execute scripts inside a Partytown Web Worker.
  2. Allow site admins to select which scripts they want to execute inside a Partytown Web Worker.

Proposal and Working of Plugin

1. Scripts with dependency as partytown will be executed inside a Web Worker.

Create a function to enqueue scripts with dependency as partytown and it will add partytown support to the script by appending the type="text/partytown" attribute.

wp_enqueue_script(
  'non-critical-script',
  plugins_url( 'non-critical-script.js', __FILE__ ),
  array('partytown'),
  '1.0.0'
);

Output:

// Loaded in Partytown Web Worker
<script type="text/partytown" src="/wp-content/plugins/labs/non-critical-script.js?ver=1.0.0"></script>

2. Expose a filter to allow plugins to configure partytown

By default Partytown does not require a config for it to work, however, a config can be set to change the defaults. At the lowest level, it’s configured by setting the window.partytown = {...} object before the Partytown snippet script.

function my_plugin_partytown_config( $config ) {
  $config["debug"] = true;
  return $config;
}
add_filter( 'partytown_configuration', 'my_plugin_partytown_config' );
<script>
    window.partytown = {
        debug: true
    };
</script>

3. Show option to enable/disable partytown on Website

To get started with Partytown on a website, you need to add a script partytown.js to your website. While the partytown.js file could be an external request, it’s recommended to inline the script instead.

Showing an option to enable it ensures that script should be included only when needed.

wp-partytown's People

Contributors

miina avatar thelovekesh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wp-partytown's Issues

Console error after plugin setup

@thelovekesh The plugin looks great! I have a problem setting up the plugin. I activated the plugin and I'm seeing an error. I didn't enqueue any script for Partytown yet. Is this a bug in the plugin or Partytown? Maybe it's on my end?

Here are some screenshots:

Screenshot 2022-09-29 at 15 32 38

Screenshot 2022-09-29 at 15 36 23

Duplicated script type

Hi
I face duplicate script type when i enable partytown for a specific js script

script type="text/partytown" type='text/javascript' ....

The script is outside Plugins and i am using this code in active theme functions.php

function wpb_adding_scripts() {
wp_register_script('my_amazing_script', get_template_directory_uri() . '/js/scripts/combine.min.js', array('partytown'),'1.0.0', true);
wp_enqueue_script('my_amazing_script');
}
add_action( 'wp_enqueue_scripts', 'wpb_adding_scripts' );

minified js

Hi
As i noticed partytown not working when i try it for Minified Javascripts ( *.min.js ) files, Do you confirm?

Is PartyTown running and perfectly configure in my website?

I'm just following a minimum tutorials and few sample config available on the internet. The documentation so minimal and need more step by step tutorial to be able to running in WordPress.

but, after many attempt, I think PartyTown is running on my website, is it right?

Please consider give explanation about my screenshot, bcs I don't know exactly. There are bunch of proxytown i saw in network tab.

Partytown js on a WordPress site https://unej.ac.id/

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.